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 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 burn the camera, please check the connection of the picture carefully before connecting.

docs-vim4-camera-os8a10

Command Line

Record Video via Gstreamer

Install Gstreamer

sudo apt update
sudo apt install gstreamer-aml

Record Video

gst-launch-1.0 v4l2src device=/dev/video50 io-mode=mmap num-buffers=300 ! amlvenc ! h264parse ! qtmux ! filesink location=test_50.mp4

Demo Source Code

This part is some Demo Source Code that will guide you how to use it to test your camera.

Install OpenCV4

$ sudo apt install libopencv-dev python3-opencv

Python

mipi-camera.py
import cv2 
 
if __name__ == '__main__':
 
    val = True
 
    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
 
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
 
    out = cv2.VideoWriter("./test.avi", fourcc, 20.0, (640, 480), True)
 
    while val is True:
        ret, frame = cap.read()
        cv2.cvtColor(frame,cv2.COLOR_RGB2BGR)
        if frame is None:
            break
        else:
            out.write(frame)
            cv2.imshow("video", frame)
            k = cv2.waitKey(1) & 0xFF
            if k == 27: 
                break
 
    cap.release()
    out.release()

Please modify the number of the open camera according to the camera node.

C++

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));
    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;
}

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

Run format:

$ ./test /dev/videoX

See Also

Last modified: 2022/10/31 23:17 by nick