MIPI camera in OpenCV

Hello there, I’m using khadas Vim3 PRO and mipi camera OS08A10 8MP HDR Camera from your official store. I tried to run camera with simple command cap = cv2.cv2.VideoCapture('/dev/video0', cv2.CAP_FFMPEG) I’m just getting infinite cycle (programm is running, but showing nothing):


My OpenCV version is 4.6 and it works perfect, because it reads photos and can connect to online stream:

MIPI camera plugged in correctly because this command shows me what she see (but then throws error in few seconds):
v4l2_test -c 1 -p 0 -F 0 -f 0 -D 0 -R 1 -r 2 -d 2 -N 1000 -n 800 -w 0 -e 1 -I 0 -b /dev/fb0 -v /dev/video0

The question - how can I capture a frame using my MIPI cam with OpenCV?

Thanks

Hello @Agent_kapo

Please check here:

https://docs.khadas.com/products/sbc/vim3/configurations/os08a10-mipi-camera#demo-source-code

Hey, I already saw this topic, the app is working, but when I’m trying it with OpenCV, he just fails, he just stucks in the infinite loop after cap = cv2.VideoCapture('/dev/video0')
If I’m putting 0 instead of /dev/video0 he just fails because he is receiving no frame.
(I tried it with OpenCV 4.2 and 4.6)

Do you have any suggestions?

Happy new year!

There is no need to make any changes to this part.

Here are some suggestions:

1.Use the latest firmware officially provided by khadas

firmware:

Install OS:

https://docs.khadas.com/products/sbc/vim3/install-os/start

2.Don’t miss every detail on the document

https://docs.khadas.com/products/sbc/vim3/configurations/os08a10-mipi-camera

Had time today to do it, but it didn’t help

Do you have different suggestions?

Hi~ @Agent_kapo

preparation
Use the latest firmware

vim3-ubuntu-20.04-gnome-linux-4.9-fenix-1.4-221229-emmc.img
http://dl.khadas.com/products/vim3/firmware/ubuntu/emmc/vim3-ubuntu-20.04-gnome-linux-4.9-fenix-1.4-221229-emmc.img.xz

Install Dependencies

sudo apt install libopencv-dev python3-opencv

Demo Source Code

    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()


Click to get the source file

https://docs.khadas.com/_export/code/products/sbc/vim3/add-ons/os08a10-mipi-camera?codeblock=4

Run

python3 ./mipi-camera.py

Thanks! That worked for me
But I have a new question, why when I plug in the mipi cam, the board turns off?

Thanks! Can you pls read my last question?

Hello~ @Agent_kapo

A lack of power can cause such problems, please use a 24W power adapter.

Please don’t hotplug the MIPI camera, when you want to plug in/out the MIPI camera you need to power off the board first.

Also, as @ivan.li mentioned, you need to use our 24W PD adaptor to make sure the board has enough power.