Can we use pthread library for opencv C++ programming? -


i have implemented opencv program can capture frames video file , process , create new file. doing single in file . want multiple files . have idea posix thread pthread library . is or bad idea . when implement pthreads in opencv program got errors following :

opencv error: assertion failed (_src.samesize(_dst) && dcn == scn) in accumulate, file /home/satinder/opencv_installation/opencv/opencv/modules/imgproc/src/accum.cpp, line 915

what(): /home/satinder/opencv_installation/opencv/opencv/modules/imgproc/src/accum.cpp:915: error: (-215) _src.samesize(_dst) && dcn == scn in function accumulate aborted (core dumped)

corrupted double-linked list: 0x00007fcd048f73d0 *** aborted (core dumped)

seg fault time .

is there possible way how can implement multi-threading or equivalent goal make program can more 1 input files same processing.

following code snapshot :

#include "opencv2/highgui/highgui.hpp" #include <sys/types.h> #include <pthread.h> #include <iostream>  using namespace cv; using namespace std;   void * videocap(void *);   void * videocap(void *arg) {          videocapture cap((char *)arg); // open video file reading      if ( !cap.isopened() )  // if not success, exit program     {          cout << "cannot open video file" << endl;          exit(1);     }      //cap.set(cv_cap_prop_pos_msec, 300); //start video @ 300ms      double fps = cap.get(cv_cap_prop_fps); //get frames per seconds of video       cout << "frame per seconds : " << fps << endl;      namedwindow("myvideo",cv_window_autosize); //create window called "myvideo"      while(1)     {         mat frame;          bool bsuccess = cap.read(frame); // read new frame video           if (!bsuccess) //if not success, break loop         {                         cout << "cannot read frame video file" << endl;                        break;         }          imshow("myvideo", frame); //show frame in "myvideo" window          if(waitkey(30) == 27) //wait 'esc' key press 30 ms. if 'esc' key pressed, break loop        {                 cout << "esc key pressed user" << endl;                 break;        }     }  }  int main(int argc, char* argv[]) {          int ret ;         pthread_t th[2];          ret = pthread_create(&th[0] , null , videocap , (void *)"cctv3.mp4");         if(0 == ret)         {                 cout << "thread 1 created successfull" << endl;         }         ret = pthread_create(&th[1] , null , videocap , (void *)"cctv10.mp4");         if(0 == ret)         {                 cout << "thread 2 created successfull" << endl;         }         pthread_join(th[0] , null);         pthread_join(th[1] , null);      return 0; } 

there problems code

namedwindow("myvideo",cv_window_autosize); //create window called "myvideo" 

you creating 2 threads, windows should have different identifiers.

namedwindow((char *)arg, cv_window_autosize); ... imshow((char *)arg, frame); 

since question posted linux tag, i'm guessing gtk relevant. after inserting directives

#include <gdk/gdk.h> #include <gtk/gtkmain.h> 

at beginning of file , in main()

pthread_t th[2];  gtk_disable_setlocale(); gtk_init(&argc, &argv);  gdk_threads_init(); 

new linker / compiler flags needed,

g++ -o -wall test.cpp -lopencv_highgui -lopencv_core `pkg-config --libs --cflags gdk-2.0 gtk+-2.0` 

after these changes there still occasional crash, added gdk_threads_enter() , gdk_threads_leave(); calls test if help:

gdk_threads_enter(); namedwindow ((char *) arg, cv_window_autosize); gdk_threads_leave(); 

since crashing not reproducible, hard tell if lines have effect.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -