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