OpenCV-在C/C ++中从默认网络摄像头获取图片-GTK问题 [英] OpenCV - Getting picture from default webcam in C/C++ - GTK Issues

查看:67
本文介绍了OpenCV-在C/C ++中从默认网络摄像头获取图片-GTK问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的GTK + v3 GUI应用程序,并且正在使用OpenCV库,因此我具有一个简单的功能,可以从连接到计算机的一个网络摄像头中拍照.该代码包含在本文的底部.

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.

我能够成功获取图像数据并将其呈现在屏幕上,但是当我将此代码包含在GTK + v3项目中时,会出现如下启动错误:

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.

到目前为止,这是有道理的.OpenCV库之一显然利用了Gtk + v2.事实证明,如果我从要链接的库列表中删除 libopencv_highgui ,则不会出现此问题.但是,出于某些原因,该库中包含用于从网络摄像头获取图像数据的功能.

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.

是否存在通过OpenCV的 C C ++ API可以访问的其他函数,这些函数不需要我使用 libopencv_highgui 并允​​许我可以轻松地从网络摄像头拍摄快照吗?

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?

另一种选择似乎是将我的项目重写为Gtk + v2应用程序,这看起来还不错,因为我对它的研究还不够深入.

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.

那里有隐藏的选项 C 吗?(对双关语原谅;)).

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;
}

推荐答案

我可以想到以下解决方案:

I can think of the following solutions:

  1. 降级到GTK 2-非常简单.

  1. Downgrade to GTK 2 - pretty simple.

由于VideoCapture是依赖的极少数模块之一highgui,请使用其他方式进行视频捕获(也许是Video4Linux)然后使用不依赖highgui的OpenCV模块.

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.

使用GTK 3支持构建OpenCV( WITH_GTK = ON WITH_GTK3 = ON ).

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

如果可以,请使用Qt代替GTK.

Use Qt instead of GTK if you can.

这篇关于OpenCV-在C/C ++中从默认网络摄像头获取图片-GTK问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆