[122] | 1 | // created: 2015/10/07
|
---|
| 2 | // filename: Sobel.cpp
|
---|
| 3 | //
|
---|
| 4 | // author: Gildas Bayard
|
---|
| 5 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 6 | //
|
---|
| 7 | // version: $Id: $
|
---|
| 8 | //
|
---|
| 9 | // purpose: Sobel
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | /*********************************************************************/
|
---|
| 13 |
|
---|
| 14 | #include "Sobel.h"
|
---|
[338] | 15 | #include "VisionFilter.h"
|
---|
| 16 | #include <Image.h>
|
---|
[122] | 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 |
|
---|
[338] | 26 | class Sobel_impl {
|
---|
| 27 | public:
|
---|
| 28 | Sobel_impl(flair::filter::Sobel *self,const LayoutPosition* position,string name):output(0) {
|
---|
| 29 | this->self=self;
|
---|
| 30 |
|
---|
| 31 | GroupBox* reglages_groupbox=new GroupBox(position,name);
|
---|
| 32 | dx=new SpinBox(reglages_groupbox->NewRow(),"dx:",0,1,1,1);
|
---|
| 33 | dy=new SpinBox(reglages_groupbox->NewRow(),"dy:",0,1,1,1);
|
---|
[122] | 34 |
|
---|
[338] | 35 | Printf("TODO: IODevice doit faire un check de GetInputDataType et GetOutputDataType\n");
|
---|
| 36 | //Image devrait accepter un type dans son constructeur pour construire un type identique
|
---|
| 37 | try{
|
---|
| 38 | Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
|
---|
| 39 | if(imageType.GetFormat()==Image::Type::Format::Gray) {
|
---|
| 40 | output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"sobel");
|
---|
| 41 | //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
|
---|
| 42 | //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
|
---|
| 43 | } else {
|
---|
| 44 | self->Err("input image is not gray\n");
|
---|
| 45 | }
|
---|
[122] | 46 |
|
---|
[338] | 47 | } catch(std::bad_cast& bc) {
|
---|
| 48 | self->Err("io type mismatch\n");
|
---|
[122] | 49 | }
|
---|
[338] | 50 | }
|
---|
[122] | 51 |
|
---|
[338] | 52 | ~Sobel_impl() {
|
---|
| 53 | //FreeFunction((char*)(inIplImage));
|
---|
| 54 | //FreeFunction((char*)(outIplImage));
|
---|
[122] | 55 | }
|
---|
[338] | 56 |
|
---|
| 57 | void UpdateFrom(const io_data *data){
|
---|
| 58 | Image *image=(Image*)data;
|
---|
| 59 | /*
|
---|
| 60 | data->GetMutex();
|
---|
| 61 | inIplImage->width=image->GetDataType().GetWidth();
|
---|
| 62 | inIplImage->height=image->GetDataType().GetHeight();
|
---|
| 63 | inIplImage->imageData=image->buffer;
|
---|
| 64 | inIplImage->imageSize=image->GetDataType().GetSize();
|
---|
| 65 |
|
---|
| 66 | output->GetMutex();
|
---|
| 67 | outIplImage->width=output->GetDataType().GetWidth();
|
---|
| 68 | outIplImage->height=output->GetDataType().GetHeight();
|
---|
| 69 | outIplImage->imageData=output->buffer;
|
---|
| 70 | outIplImage->imageSize=output->GetDataType().GetSize();
|
---|
| 71 |
|
---|
| 72 | dspSobel(inIplImage,outIplImage,dx->Value(),dy->Value());
|
---|
| 73 | output->ReleaseMutex();
|
---|
| 74 | data->ReleaseMutex();
|
---|
| 75 | */
|
---|
| 76 | output->SetDataTime(data->DataTime());
|
---|
| 77 |
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | Image *output;
|
---|
| 81 |
|
---|
| 82 | private:
|
---|
| 83 | flair::filter::Sobel *self;
|
---|
| 84 | SpinBox *dx;
|
---|
| 85 | SpinBox *dy;
|
---|
| 86 | //IplImage *inIplImage,*outIplImage;
|
---|
| 87 | };
|
---|
| 88 |
|
---|
| 89 | namespace flair { namespace filter {
|
---|
| 90 |
|
---|
| 91 | Sobel::Sobel(const IODevice* parent,const LayoutPosition* position,string name) : IODevice(parent,name) {
|
---|
| 92 | pimpl_=new Sobel_impl(this,position,name);
|
---|
[122] | 93 | }
|
---|
| 94 |
|
---|
| 95 | Sobel::~Sobel(void) {
|
---|
[338] | 96 | delete pimpl_;
|
---|
[122] | 97 | }
|
---|
| 98 |
|
---|
[338] | 99 | Image* Sobel::Output(void) {
|
---|
| 100 | return pimpl_->output;
|
---|
[122] | 101 | }
|
---|
| 102 |
|
---|
[338] | 103 | void Sobel::UpdateFrom(const io_data *data) {
|
---|
| 104 | pimpl_->UpdateFrom(data);
|
---|
| 105 | ProcessUpdate(pimpl_->output);
|
---|
[122] | 106 | }
|
---|
| 107 |
|
---|
| 108 | DataType const &Sobel::GetOutputDataType() const {
|
---|
[338] | 109 | if(pimpl_->output!=NULL) {
|
---|
| 110 | return pimpl_->output->GetDataType();
|
---|
[122] | 111 | } else {
|
---|
| 112 | return dummyType;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | } // end namespace filter
|
---|
| 117 | } // end namespace flair
|
---|