我目前正在使用OpenCV庫在樹莓派3上進行視頻處理項目。作爲閱讀opencv2計算機視覺應用程序編程手冊的指導。如果您熟悉本書,它將解釋windows visual studio上的所有內容。但是不能用cmake編譯東西。一切正常。Opencv樹莓pi 3視頻播放C++
#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();
}
在書的作者使用此代碼。而且我知道這個代碼適用於Linux的Windows等,但不是覆盆子pi。我用一張我用raspicam錄製的視頻改變了bike.avi。 raspivid -o bike.h264 -h 620 -w 480 -fps 15
。但我仍然得到Error loading video!..
。 Ps:我可以使用ssh -X播放通過vlc播放器從書籍網站下載的bike.avi視頻。
我的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})
嘗試安裝我在這裏至少建議的軟件包的第一半,看看是否有幫助... https://stackoverflow.com/a/44972255/2836621 –
@MarkSetchell其中一些不是可用於raspi,但仍然是同樣的錯誤.. – ssovukluk