使用opencv读取摄像头并且显示事出现此问题:
后来发现是图像为空时的错误,加入:
if(!frame.empty()) imshow("video",frame);
完整的代码:
int main() { /* unsigned char buf_show[1920*1080*3]; uint32_t addr_bar0; unsigned char *bar0_map_base; long int screensize = 0; unsigned char *fbp = NULL; unsigned char *ptail; Mat MatRGB ;*/ VideoCapture cap(1); if(!cap.isOpened()) printf("camre open failed!\n"); Mat frame; namedWindow("video"); if(!frame.empty()) imshow("video",frame); else printf("image empty\n"); while(1) { cap>>frame; if(!frame.empty()) imshow("video",frame); else printf("image empty\n"); if(waitKey(10)==27) break; } cap.release();
原文地址:https://www.cnblogs.com/xiaojianliu/p/9443874.html
时间: 2024-10-14 23:54:09