Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:vim4:add-ons:os08a10-mipi-camera

This is an old revision of the document!


VIM4 OS08A10 MIPI Camera

Introduction

This document mainly introduces OS08A10 MIPI Camera. The document is divided into two parts,The first part of the document describes how to connect. The second part introduces How to record video via Gstreamer and test your camera under Ubuntu.

Hardware Connection

The reverse connection will damage the camera, please check the connection of the picture carefully before connecting.

docs-vim4-camera-os8a10

Identify VIM4 Version

There are two versions of VIM4, they are VIM4 and New VIM4, as they have different ISP IP core, so the usage of MIPI camera is also different, please follow the documentation to identify your VIM4 version and choose the right documentation for your VIM4.

Please check the documentation to identify your VIM4 version.

VIM4 MIPI Camera Usage

Video Node

The video node for MIPI camera is /dev/video50.

Record Video via Gstreamer

Install Gstreamer Encoder Plugin

sudo apt update
sudo apt install gstreamer-aml

Record Video

gst-launch-1.0 v4l2src device=/dev/video50 io-mode=mmap num-buffers=300 ! video/x-raw,format=NV12 ! amlvenc bitrate=8000 ! h264parse ! qtmux ! filesink location=test_50.mp4

Record Video with OpenCV

Install OpenCV

sudo apt update
sudo apt install libopencv-dev python3-opencv

C++

Get Frame via V4l2
mipi-camera.cpp
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <string>
using
namespace  cv;
 
using
namespace  std;
 
int main(int argc, char** argv)
{
    int count=100;
    string str = argv[1];
    string res=str.substr(10);
    VideoCapture capture(stoi(res), CAP_V4L2);
    capture.set(CAP_PROP_FOURCC, VideoWriter::fourcc('U','Y','V','Y'));
    capture.set(CAP_PROP_FRAME_WIDTH, 1920);
    capture.set(CAP_PROP_FRAME_HEIGHT, 1080);
    while (count)
    {
        Mat frame;
        capture >> frame;
 
        if (frame.empty()) {
            break;
        }
        int h = frame.rows;
        int w = frame.cols;
        const char *name = "video";
        namedWindow(name, 0);
        imshow(name, frame);
        waitKey(30);
        count--;
    }
    return 0;
}
Get Frame via Gstreamer
mipi-camera.cpp
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <string>
using
namespace  cv;
 
using
namespace  std;
 
int main(int argc, char** argv)
{
    int count=100;
    string str = argv[1];
    string gstformat = "NV12";
    string gstfile = "v4l2src device=" + str + " ! video/x-raw,format=" + gstformat + ",width=1920,height=1080,framerate=30/1 ! videoconvert ! appsink";
    VideoCapture capture(gstfile);
 
    while (count)
    {
        Mat frame;
        capture >> frame;
 
        if (frame.empty()) {
            break;
        }
        int h = frame.rows;
        int w = frame.cols;
        const char *name = "video";
        namedWindow(name, 0);
        imshow(name, frame);
        waitKey(30);
        count--;
    }
    return 0;
}

Compile:

gcc -o mipi mipi-camera.cpp -lopencv_imgproc -lopencv_core -lopencv_videoio -lopencv_imgcodecs -lopencv_highgui -std=c++11 -std=gnu++11 -Wall -std=c++11 -lstdc++ -I/usr/include/opencv4

Test:

./mipi /dev/video50

New VIM4

See Also

Last modified: 2023/06/05 05:06 by nick