This guide assumes you currently have libcamera installed on your device but do not have opencv installed on your device.
- Clone this repository.
- Make sure you have libcamera installed on your device.
- Install all the dependencies required for bulding OpenCV.
- Checkout the branch
libcamera-final
using the commandgit checkout libcamera-final
. - Navigate to the cloned opencv directory and create a new build directory using
mkdir build
and thencd build
. - Set up OpenCV build with CMake, this is the configuration I am using
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_LIBCAMERA=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=ON ..
- Use
make
or usemake -j8
if your processor supports more parallel jobs for faster processing. - To install use
sudo make install
- After you are done with the installation to test the build with libcamera you can use this sample program
- To run the above file you can use
g++ libcamera_test.cpp -o libcamera_test `pkg-config --cflags --libs opencv4`
To quit the program pressq
- Capturing frames from cameras sending MJPEG and YUYV frames
- Setting some properties to configure your settings like:
- cv::CAP_PROP_FRAME_WIDTH - Change the frame width
- cv::CAP_PROP_FRAME_HEIGHT - Change the frame height
- cv::CAP_PROP_MODE - Select the PixelFormat (0 - MJPEG, 1 - YUYV, default:MJPEG)
- cv::CAP_PROP_FORMAT - Select the StreamRole (0 - Raw, 1 - StillCapture, 2 - VideoRecording, 3 - Viewfinder, default:VideoRecording)
- Getting some data using cap.get
- cv::CAP_PROP_FRAME_WIDTH - Get the current frame width
- cv::CAP_PROP_FRAME_HEIGHT - Get the current frame height
if (cap.read(frame))
has to be used to check without which crashes are observed.- NV12 support is yet to be tested.
- Multiple camera support is being worked on, at the moment you can only use one camera at a time.
- Please create new issues against this branch to notify me if you encounter an issue.
Please read the contribution guidelines before starting work on a pull request. Feel free to fork and contribute your changes.
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.