已经安装了V4l2的Pi Camera + openCV连接问题?

时间:2017-02-23 16:32:34

标签: c++ opencv raspberry-pi v4l2

我正在使用openCV来访问相机 - 由于某种原因它不会连接到pi相机,任何人都可以看到任何可能的原因吗?

我测试相机的代码如下:

#include <stdio.h>
#include <pigpio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#include <softPwm.h>
#include "move.h"
#include "init.h"
#include <iostream>
using namespace std;

#include "distance.h"
#include <linux/videodev2.h>
#include <../include/libv4l2.h>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/videoio.hpp>
using namespace cv;


void TestCamera(){

Mat initframe,blurr,B_W,edges;
//Mat image;
VideoCapture cap;
cap.open(0);
cap.set(CAP_PROP_FRAME_WIDTH,500);
cap.set(CAP_PROP_FRAME_HEIGHT,500);


 if (cap.isOpened()){


for(;;)
{
    cap.read(initframe);
    if (initframe.empty()){ printf("error frame empty/n");  break;}

imshow("Live Stream",initframe);        //normal bgr output

cvtColor(initframe,B_W,CV_BGR2GRAY);//b&W stream
imshow("greyscale",B_W);

GaussianBlur(B_W,blurr,Size(9,9),1.5,1.5);//blur applied so edge detction is smoother (less hard edges)
imshow("blurr",blurr);

Canny(blurr,edges,0,30,3);//edge detection
imshow("edges",edges);



if(waitKey(30)>= 0) break;
}
}else printf("error! unable to use camera\n");

}

,构建命令为:

g++ -Wall -I/usr/local/include $(pkg-config opencv --libs) $(pkg-config opencv --cflags) -o "SdCar" "SdCar.cpp" -lwiringPi -lpigpio -lv4l2 (in directory: /home/pi/selfdrivingcar-17)

我无法弄清楚它为什么会构建但是无论何时相机应该运行它说&#34;错误!无法打开相机&#34;这是与cap.IsOpened()函数相关的错误。

任何想法?

0 个答案:

没有答案