OpenCV - Getting picture from default webcam in C/C++ - GTK Issues

﹥>﹥吖頭↗ 提交于 2021-02-08 08:51:13

问题


I have a simple GTK+ v3 GUI application, and I am making use of the OpenCV library so that I have a simple function for taking pictures from the one webcam connected to my computer. The code is included at the bottom of this post.

I'm able to successfully acquire image data and render it on screen, but when I include this code in my GTK+ v3 project, I get a startup error like so:

(result:2944): Gtk-ERROR **: GTK+ 2.x symbols detected.
Using GTK+ 2.x and GTK+3 in the same process is not supported.
Trace/breakpoint trap.

So, this makes sense so far. One of the OpenCV libraries apparently makes use of Gtk+ v2. It turns out that if I remove libopencv_highgui from my list of libraries to link against, I won't have this issue. However, the functions used to acquire image data from the webcam is included in that library for some reason.

Are there other functions accessble via the C or C++ APIs for OpenCV that don't require me to make use of libopencv_highgui and allow me to take a snapshot from a webcam with ease?

The other alternative seem to be re-writing my project as a Gtk+ v2 application, which wouldn't be so bad, seeing as I haven't gone too far into it.

Is there a hidden option C out there? (Pardon the pun ;) ).

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>
#include <stdio.h>
#include <errno.h>

using namespace std;
using namespace cv;

#define PROJECT_NAME       "CAMERA_MODULE" // Include before liblog
#include "../../lib/liblog/inc/log.h"

int cameraAcquireImage(void) {
   CvCapture* capture = 0;
   Mat frame, frameCopy, image;

   //0=default, -1=any camera, 1..99=your camera
   capture = cvCaptureFromCAM(CV_CAP_ANY);
   if(!capture) {
      logError("No camera interface detected");
      return (-EIO);
   }

   cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
   if(capture) {
      logError("Capture in progress");
      for( ; ;) {
         IplImage* iplImg = cvQueryFrame(capture);
         frame = iplImg;

         if(frame.empty()) {
            break;
         }
         if(iplImg->origin == IPL_ORIGIN_TL) {
            frame.copyTo(frameCopy);
         } else {
            flip(frame, frameCopy, 0);
         }
         cvShowImage( "result", iplImg );
         if( waitKey( 10 ) >= 0 ) {
            break;
         }

      }
   }

   cvReleaseCapture( &capture );
   cvDestroyWindow("result");
   return 0;
}

回答1:


I can think of the following solutions:

  1. Downgrade to GTK 2 - pretty simple.

  2. Since VideoCapture is one the very few modules that depend on highgui, use something else for video capture (Video4Linux perhaps) and then use OpenCV modules which do not depend on highgui.

  3. Build OpenCV with GTK 3 support (WITH_GTK=ON WITH_GTK3=ON).

  4. Use Qt instead of GTK if you can.



来源:https://stackoverflow.com/questions/22029939/opencv-getting-picture-from-default-webcam-in-c-c-gtk-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!