0
我使用OpenCV 2.4.7,在Windows服務器2012和VS2012(更新3),提取從opencv-2.4.7.2.exe
和以下opencv教程添加所需的路徑到Windows和Visual Studio。 以下代碼在編譯後無效(返回-5),但是當我在 frame = cvQueryFrame(capture);
程序中設置斷點時有效。在此行之前和之後使用cvWaitKey(33);
,也什麼都不做。打開cv不捕獲視頻,直到設置斷點
我使用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;
}
檢查,沒有任何反應,再次設置斷點導致代碼工作。 –
我無法表達我的感受,但在第一條評論之後,我看到您的編輯和測試,兩次'frame = cvQueryFrame(capture);' –
有一個建議,請停止使用過時的C-API並開始使用C++ API。 – guneykayim