OpenCV freezing

Getting OpenCV Matrix from Macbook/Windows Desktop Using Huawei/Ubuntu and Ezcap 331 and HDMI cable

C++ chunk to get CV::Mat is below:
1
2
3
4
5
cv::VideoCapture cap(2);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1920);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1080);
cv::Mat frame;
cap.read(frame);

It gets matrix, but it takes 2-3 seconds to get one frame

Before I used other code for Windows, please find description below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
hwnd2Mat::hwnd2Mat(HWND hwindow, float scale)
{
    hwnd = hwindow;
    hwindowDC = GetDC(hwnd);
    hwindowCompatibleDC = CreateCompatibleDC(hwindowDC);
   SetStretchBltMode(hwindowCompatibleDC, COLORONCOLOR);
    RECT windowsize;
    GetClientRect(hwnd, &windowsize);
   srcheight = windowsize.bottom;
    srcwidth = windowsize.right;
    height = (int)(windowsize.bottom * scale);
    width = (int)(windowsize.right * scale);
    image.create(height, width, CV_8UC4);
    hbwindow = CreateCompatibleBitmap(hwindowDC, width, height);
    bi.biSize = sizeof(BITMAPINFOHEADER);
    bi.biWidth = width;
    bi.biHeight = -height;
    bi.biPlanes = 1;
    bi.biBitCount = 32;
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;
    SelectObject(hwindowCompatibleDC, hbwindow);
    read();

}

void hwnd2Mat::read()
{
    StretchBlt(hwindowCompatibleDC, 0, 0, width, height, hwindowDC, 0, 0, srcwidth, srcheight, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !
    GetDIBits(hwindowCompatibleDC, hbwindow, 0, height, image.data, (BITMAPINFO*)&bi, DIB_RGB_COLORS);  //copy from hwindowCompatibleDC to hbwindow
}

hwnd2Mat::~hwnd2Mat()
{
    DeleteObject(hbwindow);
    DeleteDC(hwindowCompatibleDC);
    ReleaseDC(hwnd, hwindowDC);

}

If I save matrix to file, file's size within 500 kb

Also, there is also a bug, which considered not important in some web resources

[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1

It can cause the freeze too

Please advise
Last edited on
Application/library specific questions are best asked on the forums that support them.
https://forum.opencv.org/
You're going to find the highest number of people who might be familiar with the problem.

It's like you just walked into a supermarket and asked "is there a doctor here?".

Oh, and after 50 posts, you really ought to have figured out this whole [code][/code] tag business.
already posted there, too!
Sorry, I did Edit in the morning, but server sent some errors (and forum does not work on my Ubuntu as well)

Now I need to declare global cv::VideoCapture
But
extern syntax I use does not work.
Can you please advise how to properly declare cv::VideoCapture, if I want to have access to it from different classes?
Topic archived. No new replies allowed.