|
@@ -0,0 +1,116 @@
|
|
|
+#include <iostream>
|
|
|
+#include <opencv2/opencv.hpp>
|
|
|
+#include "opencv2/imgcodecs/legacy/constants_c.h"
|
|
|
+#include <thread>
|
|
|
+#include <vector>
|
|
|
+#include "modulecomm.h"
|
|
|
+#include "cameraobject.pb.h"
|
|
|
+#include "cameraobjectarray.pb.h"
|
|
|
+#include "rawpic.pb.h"
|
|
|
+#include "imageBuffer.h"
|
|
|
+#include "ivlog.h"
|
|
|
+#include "ivfault.h"
|
|
|
+
|
|
|
+bool ivlog_flag =true;
|
|
|
+
|
|
|
+iv::Ivfault *gfault = nullptr;
|
|
|
+iv::Ivlog *givlog = nullptr;
|
|
|
+
|
|
|
+ConsumerProducerQueue<cv::Mat> * imageBuffer_sign =
|
|
|
+ new ConsumerProducerQueue<cv::Mat>(5,true);
|
|
|
+
|
|
|
+void ListenSignImage(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1000)return;
|
|
|
+ iv::vision::rawpic pic;
|
|
|
+ if(false == pic.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"picview Listenpic fail."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cv::Mat mat(pic.height(),pic.width(),pic.mattype());
|
|
|
+ if(pic.type() == 1)
|
|
|
+ memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // mat.release();
|
|
|
+ std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
|
|
|
+ mat = cv::imdecode(buff,CV_LOAD_IMAGE_COLOR);
|
|
|
+ }
|
|
|
+ imageBuffer_sign->add(mat);
|
|
|
+ mat.release();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void ListenSignArray(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ //if(nSize<10)return;
|
|
|
+ iv::vision::cameraobjectarray light_array;
|
|
|
+ if(false == light_array.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"listen signarray data fail."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i=0;i<light_array.obj_size();i++) {
|
|
|
+ std::cout<<" index: "<<light_array.obj(i).id()
|
|
|
+ <<" type: "<<light_array.obj(i).type()
|
|
|
+ <<" confidence: "<<light_array.obj(i).con()
|
|
|
+ <<" x: "<<light_array.obj(i).x()
|
|
|
+ <<" y: "<<light_array.obj(i).y()
|
|
|
+ <<" w: "<<light_array.obj(i).w()
|
|
|
+ <<" h: "<<light_array.obj(i).h()
|
|
|
+ <<std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ gfault = new iv::Ivfault("show_sign_detection");
|
|
|
+ givlog = new iv::Ivlog("show_sign_detection");
|
|
|
+ gfault->SetFaultState(0,0,"show sign detection initialize.");
|
|
|
+
|
|
|
+
|
|
|
+ //void * mpa_signarray;
|
|
|
+ //mpa_signarray= iv::modulecomm::RegisterRecv("signarray",ListenSignArray);
|
|
|
+
|
|
|
+ void * mpa_camera;
|
|
|
+ mpa_camera= iv::modulecomm::RegisterRecv("signimage",ListenSignImage);
|
|
|
+ double waittime = (double)cv::getTickCount();
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ cv::Mat sign_image;
|
|
|
+ if(imageBuffer_sign->isEmpty())
|
|
|
+ {
|
|
|
+ double waittotal = (double)cv::getTickCount() - waittime;
|
|
|
+ double totaltime = waittotal/cv::getTickFrequency();
|
|
|
+ // if(totaltime>10.0)
|
|
|
+ // {
|
|
|
+ // cout<<"Cant't get frame and quit"<<endl;
|
|
|
+ // lightstart = false;
|
|
|
+ // cv::destroyAllWindows();
|
|
|
+ // std::cout<<"------end program------"<<std::endl;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+
|
|
|
+ bool print_flag = (totaltime > 1.0);
|
|
|
+ if (print_flag)
|
|
|
+ std::cout<<"Wait for frame "<<totaltime<<"s"<<std::endl;
|
|
|
+
|
|
|
+ if(ivlog_flag & print_flag)
|
|
|
+ givlog->verbose("Wait for frame %f s",totaltime);
|
|
|
+
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ imageBuffer_sign->consume(sign_image);
|
|
|
+ cv::namedWindow("signResult",cv::WINDOW_NORMAL);
|
|
|
+ cv::imshow("signResult",sign_image);
|
|
|
+ if(cv::waitKey(10)=='q')
|
|
|
+ return 0;
|
|
|
+ //std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ //std::cout<<"show sign result"<<std::endl;
|
|
|
+ waittime = (double)cv::getTickCount();
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|