[英]Getting Input from camera opencv c++
I am always getting a grey screen when showing image using opencv, the image is captured from camera. 使用opencv显示图像时,总是出现灰色屏幕,该图像是从相机捕获的。 Any help? 有什么帮助吗?
#include "stdafx.h"
#include <opencv2\opencv.hpp>
#include <opencv2\imgcodecs.hpp>
using namespace cv;
cv::Mat takePicture() {
cv::Mat pic;
VideoCapture cam(0);
while (!cam.isOpened()) {
std::cout << "Failed to make connection to cam" << std::endl;
VideoCapture cam(0);
}
cam >> pic;
return pic;
}
int main()
{
cv::Mat pic1;
pic1 = takePicture();
imshow("camera", pic1);
}
Camera needs time to be initialized. 相机需要时间初始化。 Maybe you should change your code like this: 也许您应该像这样更改代码:
#include "stdafx.h"
#include <opencv2\opencv.hpp>
#include <opencv2\imgcodecs.hpp>
VideoCapture cam(0);
cv::Mat pic;
cv::Mat takePicture(){
while (!cam.isOpened()) {
std::cout << "Failed to make connection to cam" << std::endl;
cam.open(0);
}
cam>>pic;
return pic;
}
int main(){
cv::waitKey(1000);
cv::Mat pic1;
pic1 = takePicture();
imshow("camera", pic1);
cv::waitKey();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.