简体   繁体   中英

Opencv raspberry pi 3 video play c++

Im currently working on video processing project on raspberry pi 3 using OpenCV libraries. As a guide im reading opencv2 computer vision application programming cookbook. If you are familiar with this book, it explains everything on windows visual studio. But im able to compile things using 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. I changed bike.avi with a video that i recorded with raspicam. raspivid -o bike.h264 -h 620 -w 480 -fps 15 . But i still get Error loading video!.. . Ps: i can play bike.avi video that i downloaded from books website via vlc player using ssh -X.

My CMakeLists.txt file:

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. But when it comes using raspverry pi camera, its not supported. That is why some developers created RaspiCam libraries which works together OpenCV. They even provide cmake configurations. I installed it and capturing video around 25fps working great. This solution is for C++ users. If u are coding with python, just search python raspberry pi camera OpenCV.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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