简体   繁体   English

OpenCV树莓派3视频播放C ++

[英]Opencv raspberry pi 3 video play c++

Im currently working on video processing project on raspberry pi 3 using OpenCV libraries. 我目前正在使用OpenCV库在raspberry pi 3上进行视频处理项目。 As a guide im reading opencv2 computer vision application programming cookbook. 作为指导,我阅读了opencv2计算机视觉应用程序编程手册。 If you are familiar with this book, it explains everything on windows visual studio. 如果您熟悉这本书,它会解释Windows visual studio上的所有内容。 But im able to compile things using cmake. 但即时通讯能够使用cmake进行编译。 And everything works fine. 而且一切正常。

#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
int main()
{
// Open the video file
cv::VideoCapture capture("../bike.avi");
// check if video successfully opened
if (!capture.isOpened()){
std::cout<<"Error loading video!.."<<std::endl;
return 1;
}
// Get the frame rate
double rate= capture.get(CV_CAP_PROP_FPS);
bool stop(false);
cv::Mat frame; // current video frame
cv::namedWindow("Extracted Frame");
// Delay between each frame in ms
// corresponds to video frame rate
int delay= 1000/rate;
// for all frames in video
while (!stop) {
// read next frame if any
if (!capture.read(frame))
break;
cv::imshow("Extracted Frame",frame);
// introduce a delay
// or press key to stop
if (cv::waitKey(delay)>=0)
stop= true;
}
// Close the video file.
// Not required since called by destructor
capture.release();
}

In the book writer uses this code. 在书中作家使用此代码。 And i know this code works on linux windows etc but not on raspberry pi. 而且我知道这段代码可以在linux Windows等系统上运行,但不能在树莓派上运行。 I changed bike.avi with a video that i recorded with raspicam. 我用raspicam录制的视频更改了bike.avi。 raspivid -o bike.h264 -h 620 -w 480 -fps 15 . raspivid -o bike.h264 -h 620 -w 480 -fps 15 But i still get Error loading video!.. . 但是我仍然在Error loading video!.. Ps: i can play bike.avi video that i downloaded from books website via vlc player using ssh -X. 附言:我可以播放我通过使用ssh -X通过vlc播放器从图书网站下载的bike.avi视频。

My CMakeLists.txt file: 我的CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8)
project(salt)
FIND_PACKAGE(OpenCV REQUIRED)
add_executable(a.out main.cpp)
TARGET_LINK_LIBRARIES(a.out ${OpenCV_LIBS})

I figured out the problem. 我解决了这个问题。 OpenCV with usb webcams work fine on raspberry pi. 具有USB网络摄像头的OpenCV在树莓派上可以正常工作。 But when it comes using raspverry pi camera, its not supported. 但是,当它使用狂暴的pi相机时,它不受支持。 That is why some developers created RaspiCam libraries which works together OpenCV. 这就是为什么一些开发人员创建了可与OpenCV协同工作的RaspiCam库的原因。 They even provide cmake configurations. 他们甚至提供cmake配置。 I installed it and capturing video around 25fps working great. 我安装了它,并以25fps的速度捕获视频,效果很好。 This solution is for C++ users. 此解决方案适用于C ++用户。 If u are coding with python, just search python raspberry pi camera OpenCV. 如果您使用python进行编码,则只需搜索python树莓派相机OpenCV。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM