简体   繁体   English

使用Raspberry Pi摄像机和Open Cv显示视频时出错

[英]Error with showing video using Raspberry Pi Camera and Open Cv

When myself and my friend run this code, the output is just a black window. 当我和我的朋友运行此代码时,输​​出只是一个黑色窗口。 We expected it to start streaming video from our RaspberryPi camera. 我们希望它能够从RaspberryPi相机开始流式传输视频。 We're using a RaspberryPi, the RaspberryPi Camera, openCv, and the Raspicam Library. 我们正在使用RaspberryPi,RaspberryPi相机,openCv和Raspicam库。

Here is our code: 这是我们的代码:

#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <raspicam_cv.h>
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
  raspicam::RaspiCam_Cv Camera;
  namedWindow("color", CV_WINDOW_AUTOSIZE);
  while(1)
  {
    Mat image;
    Camera.grab();
    Camera.retrieve(image);
    imshow("color", image);
    waitKey(33);
  }
  return (0);
}

Here is a link to a tutorial we used to install the RaspiCam library. 是我们用来安装RaspiCam库的教程的链接。 If you need any more information, please let me know. 如果您需要更多信息,请告诉我。 Thanks! 谢谢!

You need to open the camera in order to use it. 您需要打开相机才能使用它。

Before your loop: 在循环之前:

if( !Camera.open() ) 
{
   std::cerr << "Cannot open the camera" << std::endl;
}

The grab() method return a boolean. capture()方法返回一个布尔值。 You can check if there is an error or not when you want to grab a picture. 想要拍摄照片时,可以检查是否有错误。

Moreover, you should specify the color encoding you want. 此外,您应该指定所需的颜色编码。 The default is RGB, but it consume many CPU. 默认值为RGB,但是它会消耗很多CPU。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (Raspberry Pi 3)如何使用set()函数(从raspicam / raspicam_cv.h)设置相机属性? - (Raspberry Pi 3) How to set camera properties using set() function (from raspicam/raspicam_cv.h)? 无法在树莓派 4 上打开网络摄像头视频 - Unable to open webcam video on raspberry pi 4 如何在c ++ openCV中使用raspberry pi摄像头作为视频输入? - how to use the raspberry pi camera as video input in c++ openCV? 打开简历相机校准 - Open cv camera calibration cv :: text :: OCRTesseract不尊重Raspberry Pi上的过滤器 - cv::text::OCRTesseract not respecting filters on Raspberry Pi 如何在Raspberry Pi上将OpenCV与C ++一起使用来加载视频文件? - How to a load video file by using OpenCV with C++ on Raspberry Pi? 如何将视频从连接到Raspberry Pi的摄像机流式传输到同一网络上的PC? - how to stream video from a camera connected to Raspberry Pi to a PC on the same network? 如何使用Win iot在Raspberry pi上显示来自Camera的视频流并进行一些图像处理 - How to display a Video stream from Camera on Raspberry pi with Win iot with some image processing 在 Raspberry Pi Stretch 上安装 opencv 3.3.0 时出现 cv2 文件中的无效转换错误 - Invalid conversion error in cv2 file while installing opencv 3.3.0 on Raspberry Pi Stretch 在Open Cv中重复播放视频 - Repeat video in Open Cv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM