blobFromImages return 1*-1*-1

when I try to use blobFromImages from Mat which reads from my capture, blobFromImages returns 1 x -1 x -1 and forward returns error.
The channels return 3.

#include<iostream>
#include<opencv2/opencv.hpp>

using namespace std;
using namespace cv;
int main()
{
	cv::dnn::Net n;
	string lss = "D:/ls/yolov5-master/yolov5-master/face_n/exp3/weights/best.onnx";
	n = dnn::readNetFromONNX(lss);
	VideoCapture cap;
	cap.open(0);
	Mat ls;
	while (1)
	{
		cap.read(ls);
		cout << ls.channels() << endl;
		ls = dnn::blobFromImages(ls, 1.0, Size(640, 640), Scalar(127,127,127), true);
		n.setInput(ls);
		Mat ls2;
		n.forward(ls2);
	}
}
  • a multi dimensional Mat (e.g. a nn Tensor) has rows & cols set to -1, please use the size member (w/o braces !) to inspect
  • you MUST check the return value from cap.read(), it WILL return invalid Mat’s, once the movie is over !
  • I check the return value from cap.read(), but there is no problem.

  • I try to use cout<<ls.size(), But the program gave me an error about the size of the returned value of blobFromImage.

OpenCV(4.7.0) Error: Assertion failed (dims() <= 2) in cv::MatSize::operator (), file C:\test\install\include\opencv2\core\mat.inl.hpp, line 1198
[1 x 480]
OpenCV(4.7.0) Error: Assertion failed (m.dims <= 2) in cv::FormattedImpl::FormattedImpl, file D:\opencv\sources\opencv-4.7.0\modules\core\src\out.cpp, line 87
[ INFO:0@28.662] global cap_msmf.cpp:546 `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

D:\source\repos\opencv_test\x64\Debug\opencv_test.exe (进程 25168)已退出,代码为 0。

In fact, it is mainly because this error will be reported when ”n.forward()“, so I came up with the problem of this function.

Now the code is like this.They still report errors when “n.forward()”

 VideoCapture cap;
    cap.open(0);
    Mat ls;
    while (1)
    {
        cap.read(ls);
        if (ls.empty())
            break;
        ls = dnn::blobFromImage(ls, 1.0, Size(640, 640), Scalar(0, 0, 0));
        n.setInput(ls);
        Mat ls2 = n.forward();
    }

hmm, any chance, you can upload the model (somewhere) ?

Hmm I just found that I will not report errors when compiling with Release, but will report errors when using Debug.

Maybe this is a stupid problem, but I really can’t solve it, so please help me find out the reason if you can.

This is the neural network of face detection. I don’t know if you can download it normally. If not, I’ll think about other ways.

(password:63aw)