Re: [問題] 用opencv開啟webcam,畫面卻是黑的
※ 引述《zx4983047 (Sun)》之銘言:
用opencv開啟webcam,畫面卻是黑的,沒有影像
而且capture跟frame都不是NULL
cvcamGetCamerasCount的值是1
請問各位大大這是為什麼呢?
感謝大家幫忙
在此附上我的程式碼
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <cvcam.h>
int main()
{
CvCapture *capture;
IplImage *frame;
int CamerasCount= cvcamGetCamerasCount();
printf("視訊裝置總數量: %d\n",CamerasCount);
capture =cvCaptureFromCAM(0) ;
if(!capture)
{return -1;}
else
{printf("Camera is OK! \n");}
cvNamedWindow("Webcam",0);
frame = cvQueryFrame(capture);
if(!frame)
{return -1;}
else
{printf("frame is OK! \n");}
while(true)
{
frame = cvQueryFrame(capture);
cvShowImage("Webcam",frame);
if(cvWaitKey(1)>=0)
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("Webcam");
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.43.63.243
→
02/05 22:44,
02/05 22:44
→
02/06 13:30,
02/06 13:30
推
02/07 01:52,
02/07 01:52
抱歉,剛忘了放程式碼,所以重PO一次
想請問各位高手如何設定capture的長跟寬?
如果再不行可能要重買一台webcam了
因為專題需要用opencv開啟webcam來做處理
而我在昨日有看到另一種程式碼
compile後可以看到影像,只是會有紅色直線
想請問為什麼會這個可以,上個程式碼卻不行? 昨日的解釋看不太懂
希望各位高手不吝指教 謝謝
在此附上另一個程式碼
#include <cvcam.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <windows.h>
void CaptureCallback(IplImage *frame1);
int main()
{
HWND CaptureWindow=0;
int width=640;
int height=480;
int CamerasCount= cvcamGetCamerasCount();
printf("視訊裝置總數量: %d\n",CamerasCount);
CameraDescription CameraDescription1;
cvcamSetProperty(0,CVCAM_PROP_ENABLE,CVCAMTRUE);
cvcamSetProperty(0,CVCAM_PROP_RENDER,CVCAMTRUE);
cvcamSetProperty(0,CVCAM_PROP_WINDOW,&CaptureWindow);
cvcamSetProperty(0,CVCAM_PROP_CALLBACK,(void *)&CaptureCallback);
cvcamSetProperty(0,CVCAM_RNDWIDTH,&width);
cvcamSetProperty(0,CVCAM_RNDHEIGHT,&height);
cvcamGetProperty(0,CVCAM_VIDEOFORMAT,NULL);
cvcamGetProperty(0,CVCAM_CAMERAPROPS,NULL);
cvcamGetProperty(0,CVCAM_DESCRIPTION,&CameraDescription1);
cvcamInit();
cvcamStart();
printf("===============================\n");
printf("選擇編號0的裝置\n");
printf("裝置名稱:\n%d\n",CameraDescription1.device);
printf("裝置描述:\n%s\n",CameraDescription1.DeviceDescription);
printf("裝置通道數:\n%d\n",CameraDescription1.channel);
printf("裝置通道描述:\n%s\n",CameraDescription1.ChannelDescription);
printf("最大寬上限:\n%d\n",CameraDescription1.maxwidth);
printf("最大高上限:\n%d\n",CameraDescription1.maxheight);
printf("最小寬上限:\n%d\n",CameraDescription1.minwidth);
printf("最小高上限:\n%d\n",CameraDescription1.minheight);
cvWaitKey(0);
cvcamStop();
cvcamExit();
}
void CaptureCallback(IplImage *frame1)
{
int i,j;
for(i=0;i<frame1->height;i+=20)
{
for(j=0;j<frame1->widthStep;j+=frame1->nChannels)
{
frame1->imageData[i*j] =0;
frame1->imageData[i*j+1]=0;
frame1->imageData[i*j+2]=255;
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.45.102.173
推
02/08 19:11, , 1F
02/08 19:11, 1F
→
02/08 19:44, , 2F
02/08 19:44, 2F
推
02/08 21:14, , 3F
02/08 21:14, 3F
→
02/08 21:14, , 4F
02/08 21:14, 4F
→
02/08 21:15, , 5F
02/08 21:15, 5F
→
02/08 21:15, , 6F
02/08 21:15, 6F
→
02/08 21:16, , 7F
02/08 21:16, 7F
→
02/08 21:17, , 8F
02/08 21:17, 8F
→
02/08 21:18, , 9F
02/08 21:18, 9F
推
02/08 21:21, , 10F
02/08 21:21, 10F
→
02/08 23:16, , 11F
02/08 23:16, 11F
→
02/08 23:19, , 12F
02/08 23:19, 12F
推
02/09 00:36, , 13F
02/09 00:36, 13F
→
02/09 00:37, , 14F
02/09 00:37, 14F
→
02/09 00:43, , 15F
02/09 00:43, 15F
推
02/09 18:50, , 16F
02/09 18:50, 16F
→
02/09 18:51, , 17F
02/09 18:51, 17F
推
02/09 23:11, , 18F
02/09 23:11, 18F
→
02/09 23:12, , 19F
02/09 23:12, 19F
→
02/10 13:23, , 20F
02/10 13:23, 20F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章