[324] | 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"
|
---|
[325] | 15 | #include "VisionFilter.h"
|
---|
[324] | 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 |
|
---|
[325] | 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);
|
---|
[324] | 33 |
|
---|
[325] | 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 | }
|
---|
[324] | 47 |
|
---|
[325] | 48 |
|
---|
[324] | 49 | }
|
---|
[325] | 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;
|
---|
[328] | 63 | inIplImage->imageSize=img->GetDataType().GetSize();
|
---|
[325] | 64 |
|
---|
| 65 | output->GetMutex();
|
---|
| 66 | outIplImage->width=output->GetDataType().GetWidth();
|
---|
| 67 | outIplImage->height=output->GetDataType().GetHeight();
|
---|
| 68 | outIplImage->imageData=output->buffer;
|
---|
[328] | 69 | outIplImage->imageSize=output->GetDataType().GetSize();
|
---|
[325] | 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 |
|
---|
| 80 | private:
|
---|
| 81 | flair::filter::ImgThreshold *self;
|
---|
| 82 | SpinBox *threshold;
|
---|
| 83 | //IplImage *inIplImage,*outIplImage;
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | namespace flair { namespace filter {
|
---|
| 87 |
|
---|
| 88 | ImgThreshold::ImgThreshold(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
|
---|
| 89 | pimpl_=new ImgThreshold_impl(this,position,name);
|
---|
[324] | 90 | }
|
---|
| 91 |
|
---|
| 92 | ImgThreshold::~ImgThreshold(void) {
|
---|
[325] | 93 | delete pimpl_;
|
---|
[324] | 94 | }
|
---|
| 95 |
|
---|
| 96 | Image* ImgThreshold::Output(void) {
|
---|
[325] | 97 | return pimpl_->output;
|
---|
[324] | 98 | }
|
---|
| 99 |
|
---|
| 100 | void ImgThreshold::UpdateFrom(const io_data *data) {
|
---|
[325] | 101 | pimpl_->UpdateFrom(data);
|
---|
| 102 | ProcessUpdate(pimpl_->output);
|
---|
[324] | 103 | }
|
---|
| 104 |
|
---|
| 105 | DataType const &ImgThreshold::GetOutputDataType() const {
|
---|
[325] | 106 | if(pimpl_->output!=NULL) {
|
---|
| 107 | return pimpl_->output->GetDataType();
|
---|
[324] | 108 | } else {
|
---|
| 109 | return dummyType;
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | } // end namespace filter
|
---|
| 114 | } // end namespace flair
|
---|