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 |
|
---|
22 | using std::string;
|
---|
23 | using namespace flair::core;
|
---|
24 | using namespace flair::gui;
|
---|
25 |
|
---|
26 | class ImgThreshold_impl {
|
---|
27 | public:
|
---|
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 |
|
---|
64 | output->GetMutex();
|
---|
65 | outIplImage->width=output->GetDataType().GetWidth();
|
---|
66 | outIplImage->height=output->GetDataType().GetHeight();
|
---|
67 | outIplImage->imageData=output->buffer;
|
---|
68 |
|
---|
69 | dspThreshold(inIplImage,outIplImage, threshold->Value(), 255, CV_THRESH_BINARY);
|
---|
70 | output->ReleaseMutex();
|
---|
71 | data->ReleaseMutex();
|
---|
72 | */
|
---|
73 | output->SetDataTime(data->DataTime());
|
---|
74 | };
|
---|
75 |
|
---|
76 | Image *output;
|
---|
77 |
|
---|
78 | private:
|
---|
79 | flair::filter::ImgThreshold *self;
|
---|
80 | SpinBox *threshold;
|
---|
81 | //IplImage *inIplImage,*outIplImage;
|
---|
82 | };
|
---|
83 |
|
---|
84 | namespace flair { namespace filter {
|
---|
85 |
|
---|
86 | ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
|
---|
87 | pimpl_=new ImgThreshold_impl(this,position,name);
|
---|
88 | }
|
---|
89 |
|
---|
90 | ImgThreshold::~ImgThreshold(void) {
|
---|
91 | delete pimpl_;
|
---|
92 | }
|
---|
93 |
|
---|
94 | Image* ImgThreshold::Output(void) {
|
---|
95 | return pimpl_->output;
|
---|
96 | }
|
---|
97 |
|
---|
98 | void ImgThreshold::UpdateFrom(const io_data *data) {
|
---|
99 | pimpl_->UpdateFrom(data);
|
---|
100 | ProcessUpdate(pimpl_->output);
|
---|
101 | }
|
---|
102 |
|
---|
103 | DataType const &ImgThreshold::GetOutputDataType() const {
|
---|
104 | if(pimpl_->output!=NULL) {
|
---|
105 | return pimpl_->output->GetDataType();
|
---|
106 | } else {
|
---|
107 | return dummyType;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | } // end namespace filter
|
---|
112 | } // end namespace flair
|
---|