c - GTK Application doesn't refresh UI when using OpenCV -


i have simple gui application wrote in c raspberry pi while using gtk+2.0 handle actual ui rendering. application far pretty simple, few pushbuttons testing simple functions wrote. 1 button causes thread woken prints text console, , goes sleep, while button stops operation locking mutex, changing status variable, unlocking mutex again. simple stuff far. point of using threaded approach don't ever "lock up" ui during long function call, forcing user blocked on i/o operations completing before ui usable again.

if call following function in thread's processing loop, encounter number of issues.

#include <opencv2/objdetect/objdetect.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp>  #include <stdio.h> #include <errno.h>  using namespace std; using namespace cv;  #define project_name       "camera_module" // include before liblog #include <log.h>  int cameraacquireimage(char* pathtoimage) {    if (!pathtoimage) {       logerror("invalid input");       return (-einval);    }    int ierr = 0;    cvcapture *capture = null;    iplimage *frame, *img;     //0=default, -1=any camera, 1..99=your camera    capture = cvcapturefromcam(cv_cap_any);    if(!capture) {       logerror("no camera interface detected");       ierr = (-eio);    }    if (!ierr) {       if ((frame = cvqueryframe(capture)) == null) {          logerror("error: frame null...");          ierr = (-eio);       }    }    if (!ierr) {       cvsize size = cvsize(100, 100);       if ((img = cvcreateimage(size, ipl_depth_16s, 1)) != null) {          img = frame;          cvsaveimage(pathtoimage, img);       }    }    if (capture) {       cvreleasecapture(&capture);    }    return 0; } 

the function uses simple opencv code take snapshot webcam connected raspberry pi. issues warnings of vidioc_querymenu: invalid argument console, still manages acquire images , save them file me. however, gui becomes sluggish, , hangs. if doesn't outright hang, window goes blank, , have randomly click on ui area until click on pushbutton located, , ui re-renders again rather showing white empty layout.

how go resolving this? quirk in opencv when using part of gtk+2.0 application? had had project setup gtk3.0 application, wouldn't run due check in gtk preventing multiple versions being included in single application, , seems opencv extension of gtk+2.0.

thank you.

there quite broken here:

  cvsize size = cvsize(100, 100);   if ((img = cvcreateimage(size, ipl_depth_16s, 1)) != null) {      img = frame;      cvsaveimage(pathtoimage, img);   } 

first, create useless 16-bit image (why even?), reassign(alias) pointer original image, , don't cvreleaseimage (memleak).

please, stop using opencv's deprecated c-api. please.

any noob will shoot foot using (one of main reasons rid of it)

also, can use ~30% of opencv's functionality way (the opencv1.0 set)

again, please, stop using opencv's deprecated c-api. please.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -