我在Windows服务器2012和VS2012(更新3)上使用OpenCV 2.4.7,从opencv-2.4.7.2.exe
中提取并在opencv教程后面添加了windows和visual studio所需的路径。
以下代码在构建后不起作用(返回-5),但是当我在中设置断点时
frame = cvQueryFrame(capture);
计划有效。在此行之前和之后使用cvWaitKey(33);
,也不执行任何操作。
我使用a4tech网络摄像头,使用一些没有问题的网络摄像头软件进行测试。我也没有任何第三方dll喜欢tbb。
在visual studio输出窗口中,我得到以下这些:
'test1.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'L:\Projects\opencv\opencv\build\x64\vc11\bin\opencv_core247d.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'L:\Projects\opencv\opencv\build\x64\vc11\bin\opencv_imgproc247d.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'L:\Projects\opencv\opencv\build\x64\vc11\bin\opencv_highgui247d.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msvcp110d.dll'. Symbols loaded.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msvcr110d.dll'. Symbols loaded.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.9200.16658_none_776622cb3175a40c\comctl32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msvfw32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\avifil32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\avicap32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\winmm.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msacm32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\version.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\winmmbase.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\clbcatq.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\devenum.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\setupapi.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\cfgmgr32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\devobj.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\ntmarta.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\wintrust.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\crypt32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msasn1.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msdmo.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\qcap.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\quartz.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\dwmapi.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\ksproxy.ax'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\ksuser.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\d3d9.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\vidcap.ax'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\Kswdmcap.ax'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\mfc42.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\odbc32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\qedit.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\comdlg32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\WinSxS \amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9200.16518_none_726fbfe0cc22f012\GdiPlus.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\ddraw.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\dciman32.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Loaded 'C:\Windows\System32\igdumd64.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Unloaded 'C:\Windows\System32\igdumd64.dll'
'test1.exe' (Win32): Loaded 'C:\Windows\System32\igdumd64.dll'. Cannot find or open the PDB file.
'test1.exe' (Win32): Unloaded 'C:\Windows\System32\igdumd64.dll'
'test1.exe' (Win32): Loaded 'C:\Windows\System32\msyuv.dll'. Cannot find or open the PDB file.
The thread 0x1efc has exited with code -5 (0xfffffffb).
The thread 0x1540 has exited with code -5 (0xfffffffb).
The thread 0x1160 has exited with code -5 (0xfffffffb).
The thread 0x1af8 has exited with code -5 (0xfffffffb).
The thread 0x1c84 has exited with code -5 (0xfffffffb).
这段代码有什么问题?还是我的配置?
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
IplImage* imgTracking;
int lastX = -1;
int lastY = -1;
//This function threshold the HSV image and create a binary image
IplImage* GetThresholdedImage(IplImage* imgHSV){
IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
cvInRangeS(imgHSV, cvScalar(160,160,60), cvScalar(180,256,256), imgThresh);
return imgThresh;
}
void trackObject(IplImage* imgThresh){
// Calculate the moments of 'imgThresh'
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
cvMoments(imgThresh, moments, 1);
double moment10 = cvGetSpatialMoment(moments, 1, 0);
double moment01 = cvGetSpatialMoment(moments, 0, 1);
double area = cvGetCentralMoment(moments, 0, 0);
if(area>1000){
// calculate the position of the ball
int posX = moment10/area;
int posY = moment01/area;
if(lastX>=0 && lastY>=0 && posX>=0 && posY>=0) {
// Draw a line from the previous point to the current point
cvLine(imgTracking, cvPoint(posX, posY), cvPoint(lastX, lastY), cvScalar(0,0,255), 4);
}
lastX = posX;
lastY = posY;
}
free(moments);
}
int main(){
CvCapture* capture =0;
//....1....cvWaitKey(500); this does nothing
capture = cvCaptureFromCAM(0);
//Following line also tested, and nothing happened
//cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 640 );
//cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 480 );
if(!capture){
printf("Capture failure\n");
return -10;
}
IplImage* frame=0;
//....2....cvWaitKey(33); 33 ms delay, does nothing at all
frame = cvQueryFrame(capture);
//....3....cvWaitKey(33); 33 ms delay, does nothing at all
if(!frame) return -5;
//create a blank image and assigned to 'imgTracking' which has the same size of original video
imgTracking=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U, 3);
//covert the image, 'imgTracking' to black
cvZero(imgTracking);
cvNamedWindow("Video");
cvNamedWindow("Ball");
//iterate through each frames of the video
while(true){
frame = cvQueryFrame(capture);
if(!frame) break;
frame=cvCloneImage(frame);
//smooth the original image using Gaussian kernel
cvSmooth(frame, frame, CV_GAUSSIAN,3,3);
IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
//Change the color format from BGR to HSV
cvCvtColor(frame, imgHSV, CV_BGR2HSV);
IplImage* imgThresh = GetThresholdedImage(imgHSV);
//smooth the binary image using Gaussian kernel
cvSmooth(imgThresh, imgThresh, CV_GAUSSIAN,3,3);
//track the possition of the ball
trackObject(imgThresh);
// Add the tracking image and the frame
cvAdd(frame, imgTracking, frame);
cvShowImage("Ball", imgThresh);
cvShowImage("Video", frame);
//Clean up used images
cvReleaseImage(&imgHSV);
cvReleaseImage(&imgThresh);
cvReleaseImage(&frame);
//Wait 10mS
int c = cvWaitKey(33);
//If 'ESC' is pressed, break the loop
if((char)c==27 ) break;
}
cvDestroyAllWindows() ;
cvReleaseImage(&imgTracking);
cvReleaseCapture(&capture);
return 0;
}
答案 0 :(得分:1)
//....2....cvWaitKey(33); 33 ms delay, does nothing at all
这是预期的行为,因为如果有一个打开的窗口它会等待33毫秒。如果你想让这些线条工作,你应该在那一行之前打开一个窗口。
尝试两次运行第frame = cvQueryFrame(capture);
行,由于某种原因,它可能无法捕获第一行中的图像,只是尝试一下。