View simply camera opencv4.5

Hello,
I try to use opencv with my camera MIPI in VIM3.

#include <opencv4/opencv2/highgui/highgui.hpp>
#include <opencv4/opencv2/imgproc/imgproc.hpp>
#include <opencv4/opencv2/core/core.hpp>
#include
#include
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(CV_CAP_PROP_FRAME_WIDTH, 1920);
// capture.set(CV_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";
   // cvNamedWindow(name, 0);
   // cvResizeWindow(name, w / 1, h / 1);
    imshow(name, frame);
    waitKey(30);
    count--;
}
return 0;

}

My output is :
.khadas@Khadas:/npu/camera_test/program_c_opencv4$ ./a.out /dev/video0
[ WARN:0] global /home/khadas/opencv-build/opencv-master/modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video0): can’t open camera by index

how I use opencv4 for open camera ?

@ronron Which camera model you used ? usb camera or mipi camera ?

it is a mipi camera wich work on opencv2 :wink:

@ronron I have test with opencv 4.2 in my NPU demo, but I don’t test with opencv4.5.
How did you install opencv4.5, did you compile it on the board?

I recompiled opencv from github without using the ffmpeg lib which causes compilation errors.

@ronron Maybe you can try with opencv4.2 ? I think you app can run with opencv4.2 too.

I am not sure that will there be any problems with your compilation options. opencv4.2 is an official version with ubuntu20.04.

Uninstall the version of opencv you compiled online, or re-burn the firmware,then

$ sudo apt remove opencv3
$ sudo apt update
$ sudo apt install libopencv-dev python3-opencv
1 Like

Hello frank,
I reset my SD card with the file VIM3_Ubuntu-server-focal_Linux-4.9_arm64_SD-USB_V0.9-20200530.7z.
Execute the 3 commands and it is works :slight_smile: with argument " -I /usr/include/opencv4 " :wink:

FYI, I made a go-lang program and it also works correctly :wink:

1 Like

但是在软件源中不提供4.2版本的opencv-python,我试过了4.6以及3.4,均无法调用
image