├── GStreamer_RPi_64_Bullseye.cbp ├── LICENSE ├── README.md └── main.cpp /GStreamer_RPi_64_Bullseye.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 55 | 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, Q-engineering 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Libcamera OpenCV RPi Bullseye 64OS 2 | ![output image]( https://qengineering.eu/images/CameraWall.webp )
3 | ## Libcamera + OpenCV on a Raspberry Pi 4 with 64-bit Bullseye OS 4 | [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

5 | In the new Debian 11, Bullseye, you can only capture live video with a streaming framework, like GStreamer or FFmpeg. This is an example of libcamera working on a Raspberry Pi with an 64-bits OS.
6 | 7 | ------------ 8 | 9 | ## Dependencies.
10 | To run the application, you have to: 11 | - A Raspberry Pi 4. 12 | - GStreamer 1.18.4 installed. [Install GStreamer](https://qengineering.eu/install-gstreamer-1.18-on-raspberry-pi-4.html)
13 | - OpenCV 64 bit installed. [Install OpenCV 4.5](https://qengineering.eu/install-opencv-4.5-on-raspberry-64-os.html)
14 | - Code::Blocks installed. (```$ sudo apt-get install codeblocks```) 15 | - A working Raspicam 16 | 17 | ------------ 18 | 19 | ## Installing the app. 20 | To extract and run the app in Code::Blocks
21 | $ mkdir *MyDir*
22 | $ cd *MyDir*
23 | $ wget https://github.com/Qengineering/Libcamera-OpenCV-RPi-Bullseye-64OS/archive/refs/heads/main.zip
24 | $ unzip -j master.zip
25 | Remove master.zip, LICENSE and README.md as they are no longer needed.
26 | $ rm master.zip
27 | $ rm LICENSE
28 | $ rm README.md

29 | Your *MyDir* folder must now look like this:
30 | GStreamer_RPi_64_Bullseye.cpb
31 | main.cpp
32 | 33 | ------------ 34 | 35 | ## Running the app. 36 | To run the application load the project file GStreamer_RPi_64_Bullseye.cbp in Code::Blocks.
37 | Next, follow the instructions at [Hands-On](https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html#HandsOn).
38 | On this [page](https://qengineering.eu/install-gstreamer-1.18-on-raspberry-pi-4.html) you can see how to make the **webcam** work. 39 | 40 | ------------ 41 | 42 | ## Frame rate. 43 | The Raspicam supports many sizes and frame rates, as you can see [here](https://www.raspberrypi.org/documentation/raspbian/applications/camera.md).
44 | You can switch between the different options by altering the parameters in the pipeline.
45 | As long it's a valid combination, it will work. For instance:
46 | ``` 47 | //pipeline parameters 48 | int capture_width = 640 ; 49 | int capture_height = 480 ; 50 | int display_width = 640 ; 51 | int display_height = 480 ; 52 | int framerate = 90 ; 53 | ``` 54 | 55 | ------------ 56 | 57 | [![paypal](https://qengineering.eu/images/TipJarSmall4.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CPZTM5BB3FCYL) 58 | 59 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /// For the Raspberry Pi 64-bit Bullseye OS 4 | 5 | std::string gstreamer_pipeline(int capture_width, int capture_height, int framerate, int display_width, int display_height) { 6 | return 7 | " libcamerasrc ! video/x-raw, " 8 | " width=(int)" + std::to_string(capture_width) + "," 9 | " height=(int)" + std::to_string(capture_height) + "," 10 | " framerate=(fraction)" + std::to_string(framerate) +"/1 !" 11 | " videoconvert ! videoscale !" 12 | " video/x-raw," 13 | " width=(int)" + std::to_string(display_width) + "," 14 | " height=(int)" + std::to_string(display_height) + " ! appsink"; 15 | } 16 | 17 | int main() 18 | { 19 | //pipeline parameters 20 | int capture_width = 640; //1280 ; 21 | int capture_height = 480; //720 ; 22 | int framerate = 15 ; 23 | int display_width = 640; //1280 ; 24 | int display_height = 480; //720 ; 25 | 26 | //reset frame average 27 | std::string pipeline = gstreamer_pipeline(capture_width, capture_height, framerate, 28 | display_width, display_height); 29 | std::cout << "Using pipeline: \n\t" << pipeline << "\n\n\n"; 30 | 31 | cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER); 32 | if(!cap.isOpened()) { 33 | std::cout<<"Failed to open camera."<