raspberry pi 3 video play c++

asked 2017-08-06 16:29:29 -0500

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.

int main()
// Open the video file
cv::VideoCapture capture("bike.avi");
// check if video successfully opened
if (!capture.isOpened())
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))
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

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!... (RETURNS 1)

My CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
project(a.out) FIND_PACKAGE(OpenCV REQUIRED)
add_executable(a.out main.cpp)

edit retag flag offensive close merge delete