source: flair-src/trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp@ 419

Last change on this file since 419 was 338, checked in by Sanahuja Guillaume, 3 years ago

remove opencv dep

File size: 3.3 KB
Line 
1// created: 2015/10/07
2// filename: ImgThreshold.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: ImgThreshold
10//
11//
12/*********************************************************************/
13
14#include "ImgThreshold.h"
15#include "VisionFilter.h"
16#include <Image.h>
17#include <Layout.h>
18#include <GroupBox.h>
19#include <SpinBox.h>
20#include <typeinfo>
21
22using std::string;
23using namespace flair::core;
24using namespace flair::gui;
25
26class ImgThreshold_impl {
27public:
28 ImgThreshold_impl(flair::filter::ImgThreshold *self,const LayoutPosition* position,string name):output(0) {
29 this->self=self;
30
31 GroupBox* reglages_groupbox=new GroupBox(position,name);
32 threshold=new SpinBox(reglages_groupbox->NewRow(),"threshold:",0,255,1,127);
33
34 Printf("todo: pouvoir reutiliser la meme image en sortie\n");
35 try{
36 Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
37 if(imageType.GetFormat()==Image::Type::Format::Gray) {
38 output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold");
39 //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
40 //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
41 } else {
42 self->Err("input image is not gray\n");
43 }
44 } catch(std::bad_cast& bc) {
45 self->Err("io type mismatch\n");
46 }
47
48
49 }
50
51 ~ImgThreshold_impl() {
52 //FreeFunction((char*)(inIplImage));
53 //FreeFunction((char*)(outIplImage));
54 }
55
56 void UpdateFrom(const io_data *data){
57 Image *img=(Image*)data;
58/*
59 data->GetMutex();
60 inIplImage->width=img->GetDataType().GetWidth();
61 inIplImage->height=img->GetDataType().GetHeight();
62 inIplImage->imageData=img->buffer;
63 inIplImage->imageSize=img->GetDataType().GetSize();
64
65 output->GetMutex();
66 outIplImage->width=output->GetDataType().GetWidth();
67 outIplImage->height=output->GetDataType().GetHeight();
68 outIplImage->imageData=output->buffer;
69 outIplImage->imageSize=output->GetDataType().GetSize();
70
71 dspThreshold(inIplImage,outIplImage, threshold->Value(), 255, CV_THRESH_BINARY);
72 output->ReleaseMutex();
73 data->ReleaseMutex();
74*/
75 output->SetDataTime(data->DataTime());
76 };
77
78 Image *output;
79
80private:
81 flair::filter::ImgThreshold *self;
82 SpinBox *threshold;
83 //IplImage *inIplImage,*outIplImage;
84};
85
86namespace flair { namespace filter {
87
88ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
89 pimpl_=new ImgThreshold_impl(this,position,name);
90}
91
92ImgThreshold::~ImgThreshold(void) {
93 delete pimpl_;
94}
95
96Image* ImgThreshold::Output(void) {
97 return pimpl_->output;
98}
99
100void ImgThreshold::UpdateFrom(const io_data *data) {
101 pimpl_->UpdateFrom(data);
102 ProcessUpdate(pimpl_->output);
103}
104
105DataType const &ImgThreshold::GetOutputDataType() const {
106 if(pimpl_->output!=NULL) {
107 return pimpl_->output->GetDataType();
108 } else {
109 return dummyType;
110 }
111}
112
113} // end namespace filter
114} // end namespace flair
Note: See TracBrowser for help on using the repository browser.