[122] | 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 <cvimage.h>
|
---|
| 16 | #include <Layout.h>
|
---|
| 17 | #include <GroupBox.h>
|
---|
| 18 | #include <SpinBox.h>
|
---|
| 19 | #include <typeinfo>
|
---|
| 20 |
|
---|
| 21 | using std::string;
|
---|
| 22 | using namespace flair::core;
|
---|
| 23 | using namespace flair::gui;
|
---|
| 24 |
|
---|
| 25 | namespace flair { namespace filter {
|
---|
| 26 |
|
---|
| 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 | cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
|
---|
[124] | 34 | if(imageType.GetFormat()==cvimage::Type::Format::Gray) {
|
---|
[122] | 35 | output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold");
|
---|
| 36 | } else {
|
---|
[124] | 37 | Err("input image is not gray\n");
|
---|
[157] | 38 | return;
|
---|
[122] | 39 | }
|
---|
| 40 | } catch(std::bad_cast& bc) {
|
---|
| 41 | Err("io type mismatch\n");
|
---|
[157] | 42 | return;
|
---|
[122] | 43 | }
|
---|
[157] | 44 | SetIsReady(true);
|
---|
[122] | 45 | }
|
---|
| 46 |
|
---|
| 47 | ImgThreshold::~ImgThreshold(void) {
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | cvimage* ImgThreshold::Output(void) {
|
---|
| 51 | return output;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | void ImgThreshold::UpdateFrom(const io_data *data) {
|
---|
| 55 | cvimage *cvImage=(cvimage*)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);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | DataType const &ImgThreshold::GetOutputDataType() const {
|
---|
| 69 | if(output!=NULL) {
|
---|
| 70 | return output->GetDataType();
|
---|
| 71 | } else {
|
---|
| 72 | return dummyType;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | } // end namespace filter
|
---|
| 77 | } // end namespace flair
|
---|