2 u013435216 u013435216 于 2014.01.11 22:19 提问

opencv 摄像头捕捉时窗口是灰色

摄像头指示灯有亮,但就是没有视频
code都在下面 哪位大神能给解答?感激不尽。
#include "stdafx.h"

#include
#include

int lowerH=0;
int lowerS=0;
int lowerV=0;

int upperH=180;
int upperS=256;
int upperV=256;

//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(lowerH,lowerS,lowerV), cvScalar(upperH,upperS,upperV), imgThresh);  

return imgThresh;

}

//This function create two windows and 6 trackbars for the "Ball" window
void setwindowSettings(){
cvNamedWindow("Video");
cvNamedWindow("Ball");

cvCreateTrackbar("LowerH", "Ball", &lowerH, 180, NULL);
cvCreateTrackbar("UpperH", "Ball", &upperH, 180, NULL);

cvCreateTrackbar("LowerS", "Ball", &lowerS, 256, NULL);
cvCreateTrackbar("UpperS", "Ball", &upperS, 256, NULL);

cvCreateTrackbar("LowerV", "Ball", &lowerV, 256, NULL);
cvCreateTrackbar("UpperV", "Ball", &upperV, 256, NULL); 

}

int main(){
CvCapture* capture =cvCaptureFromAVI("C:/1.wmv");

/*capture = cvCaptureFromCAM(0);
if(!capture){
        printf("Capture failure\n");
        return -1;
}*/

IplImage* frame=0;

setwindowSettings();

//iterate through each frames of the video
while(true){

    frame = cvQueryFrame(capture);
    if(!frame)  break;
    frame=cvCloneImage(frame);  

    IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);    
    cvCvtColor(frame, imgHSV, CV_BGR2HSV); //Change the color format from BGR to HSV

    IplImage* imgThresh = GetThresholdedImage(imgHSV);

    cvShowImage("Ball", imgThresh);
    cvShowImage("Video", frame);

    //Clean up used images
    cvReleaseImage(&imgHSV);
    cvReleaseImage(&imgThresh);
    cvReleaseImage(&frame);

    //Wait 80mS
    int c = cvWaitKey(80);
    //If 'ESC' is pressed, break the loop
    if((char)c==27 )    break;

}

cvDestroyAllWindows();
cvReleaseCapture(&capture);

return 0;

}

1个回答

qinzhen353
qinzhen353   2014.01.16 00:16

你的代码好像不是捕获摄像头吧。。那个代码被你注释掉了啊,就是capture = cvCaptureFromCAM(0);这句,这才是捕获摄像头的。

u011140645
u011140645 想知道怎么解决窗体为什么是灰色的
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!