March 2019
Intermediate to advanced
312 pages
7h 37m
English
We will now write a simple C++ program to view the camera feed from the Pi camera. The program for viewing the video is as follows. The program is named Camerafeed.cpp and you can download it from the Chaper07 folder of the GitHub repository:
int main(){ Mat videoframe; VideoCapture vid(0); if (!vid.isOpened()) {cout<<"Error opening camera"<<endl; return -1; } for(;;) { vid.read(videoframe); imshow("Frame", videoframe); if (waitKey(1) > 0) break; } return 0;}
The OpenCV libraries and namespace declaration is similar to that of the previous program: