Changeset 325 in flair-src for branches/sanscv/lib/FlairVisionFilter/src/ImgThreshold.cpp
- Timestamp:
- 08/28/19 16:12:11 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sanscv/lib/FlairVisionFilter/src/ImgThreshold.cpp
r324 r325 13 13 14 14 #include "ImgThreshold.h" 15 #include "VisionFilter.h" 15 16 #include <Image.h> 16 17 #include <Layout.h> 17 18 #include <GroupBox.h> 18 19 #include <SpinBox.h> 20 //#include <dspcv_gpp.h> 19 21 #include <typeinfo> 20 22 … … 23 25 using namespace flair::gui; 24 26 27 class ImgThreshold_impl { 28 public: 29 ImgThreshold_impl(flair::filter::ImgThreshold *self,const LayoutPosition* position,string name):output(0) { 30 this->self=self; 31 32 GroupBox* reglages_groupbox=new GroupBox(position,name); 33 threshold=new SpinBox(reglages_groupbox->NewRow(),"threshold:",0,255,1,127); 34 35 Printf("todo: pouvoir reutiliser la meme image en sortie\n"); 36 try{ 37 Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType()); 38 if(imageType.GetFormat()==Image::Type::Format::Gray) { 39 output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold"); 40 //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage)); 41 //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage)); 42 } else { 43 self->Err("input image is not gray\n"); 44 } 45 } catch(std::bad_cast& bc) { 46 self->Err("io type mismatch\n"); 47 } 48 49 50 } 51 52 ~ImgThreshold_impl() { 53 //FreeFunction((char*)(inIplImage)); 54 //FreeFunction((char*)(outIplImage)); 55 } 56 57 void UpdateFrom(const io_data *data){ 58 Image *img=(Image*)data; 59 /* 60 data->GetMutex(); 61 inIplImage->width=img->GetDataType().GetWidth(); 62 inIplImage->height=img->GetDataType().GetHeight(); 63 inIplImage->imageData=img->buffer; 64 65 output->GetMutex(); 66 outIplImage->width=output->GetDataType().GetWidth(); 67 outIplImage->height=output->GetDataType().GetHeight(); 68 outIplImage->imageData=output->buffer; 69 70 dspThreshold(inIplImage,outIplImage, threshold->Value(), 255, CV_THRESH_BINARY); 71 output->ReleaseMutex(); 72 data->ReleaseMutex(); 73 */ 74 output->SetDataTime(data->DataTime()); 75 }; 76 77 Image *output; 78 79 private: 80 flair::filter::ImgThreshold *self; 81 SpinBox *threshold; 82 //IplImage *inIplImage,*outIplImage; 83 }; 84 25 85 namespace flair { namespace filter { 26 86 27 ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name),output(0) { 28 GroupBox* reglages_groupbox=new GroupBox(position,name); 29 threshold=new SpinBox(reglages_groupbox->NewRow(),"threshold:",0,255,1,127); 30 31 Printf("todo: pouvoir reutiliser la meme image en sortie\n"); 32 try{ 33 Image::Type const &imageType=dynamic_cast<Image::Type const &>(parent->GetOutputDataType()); 34 if(imageType.GetFormat()==Image::Type::Format::Gray) { 35 output=new Image(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold"); 36 } else { 37 Err("input image is not gray\n"); 38 return; 39 } 40 } catch(std::bad_cast& bc) { 41 Err("io type mismatch\n"); 42 return; 43 } 44 SetIsReady(true); 87 ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) { 88 pimpl_=new ImgThreshold_impl(this,position,name); 45 89 } 46 90 47 91 ImgThreshold::~ImgThreshold(void) { 92 delete pimpl_; 48 93 } 49 94 50 95 Image* ImgThreshold::Output(void) { 51 return output;96 return pimpl_->output; 52 97 } 53 98 54 99 void ImgThreshold::UpdateFrom(const io_data *data) { 55 /* Image *cvImage=(Image*)data; 56 IplImage *gimg=cvImage->img; 57 58 data->GetMutex(); 59 output->GetMutex(); 60 dspThreshold(gimg, output->img, threshold->Value(), 255, CV_THRESH_BINARY); 61 output->ReleaseMutex(); 62 data->ReleaseMutex(); 63 */ 64 output->SetDataTime(data->DataTime()); 65 ProcessUpdate(output); 100 pimpl_->UpdateFrom(data); 101 ProcessUpdate(pimpl_->output); 66 102 } 67 103 68 104 DataType const &ImgThreshold::GetOutputDataType() const { 69 if( output!=NULL) {70 return output->GetDataType();105 if(pimpl_->output!=NULL) { 106 return pimpl_->output->GetDataType(); 71 107 } else { 72 108 return dummyType;
Note:
See TracChangeset
for help on using the changeset viewer.