Opencv terminate handler is called the last opencv error is

Cannot load the onnx model converted from pytorch #16971 Comments System information (version) OpenCV => OpenCV => 4.3.0(e6f32c6a69043456a806a4e802ee3ce7b7059c93) Operating System / Platform => Windows 64 Bit Compiler => Visual Studio 2017 64 bits Detailed description The decoder model converted from this project do not work. Steps to reproduce install pytorch 1.4.0(cpu version) clone the […]

Содержание

  1. Cannot load the onnx model converted from pytorch #16971
  2. Comments
  3. matrix_expressions.cpp:24: error: (-5:Bad argument) Matrix operand is an empty matrix. in function ‘cv::checkOperandsExist’ #18572
  4. Comments
  5. matrix_expressions.cpp:24: error: (-5:Bad argument) Matrix operand is an empty matrix. in function ‘cv::checkOperandsExist’ #18572
  6. Comments
  7. Opencv loads models of dynamic input types #19347
  8. Comments
  9. import Tensorflow 2.x PB via readNetFromTensorflow DNN api function (C++) #16879
  10. Comments

Cannot load the onnx model converted from pytorch #16971

System information (version)
  • OpenCV => OpenCV => 4.3.0(e6f32c6a69043456a806a4e802ee3ce7b7059c93)
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2017 64 bits
Detailed description

The decoder model converted from this project do not work.

Steps to reproduce
  1. install pytorch 1.4.0(cpu version)
  2. clone the project
  3. Navigate to the folder of the project, create a file called to_onnx.py
  1. Change the class ResnetEncoder in networks/resnet_encoder.py to
  1. Change the class DepthDecoder in networks/depth_decoder.py to

Both of the decoder and encoder models passed the test.

To save your troubles, you can have the graph,model and codes(to_onnx.py, resnet_encoder.py, depth_decoder.py) from google drive.

Issue submission checklist

Cannot load the encoder model after convert, got error messages

OpenCV: terminate handler is called! The last OpenCV error is:OpenCV(4.3.0-pre) Error: Assertion failed (shapeIt != outShapes.end()) in cv::dnn::dnn4_v20200310::ONNXImporter::populateNet, file C:UsersyyyyprogramsQt3rdLibsopencvdevopencvmodulesdnnsrconnxonnx_importer.cpp, line 1116

The text was updated successfully, but these errors were encountered:

Источник

matrix_expressions.cpp:24: error: (-5:Bad argument) Matrix operand is an empty matrix. in function ‘cv::checkOperandsExist’ #18572

environment:
OpenCV(4.3.0)
language:python 3.6

1.load the data from txt files,and then convert type from float to int32.
a.txt
4.020161 0.372046
4.086024 0.548271
4.112598 0.539363
4.162546 0.522878
4.252789 0.684608
4.265030 0.681673
4.572025 0.757398
4.752093 0.743017
4.958206 0.821787
5.138208 0.807434
5.298540 0.906368
5.542401 0.878399
5.798231 1.013368
6.018507 1.075400
6.113993 1.135273
6.425354 1.265514
6.545009 1.264395
6.731231 1.205198
6.901707 1.293404
7.236600 1.293581
7.264717 1.276446
7.542284 1.294016
7.849143 1.123871
7.888957 0.818015

b.txt
0.558444 0.486612
0.590397 0.479795
0.637800 0.728716
0.688097 0.927678
0.911380 1.735989
0.946417 1.752804
1.247624 2.280543
1.341965 2.214138
1.552272 2.264075
1.891904 2.235193
1.943452 2.234293
2.129528 2.216326
2.370298 2.131144
2.654617 2.204402
2.769804 2.168312
2.967309 2.118495
3.258043 2.180414
3.386168 2.172515
3.582158 2.205668
3.909915 2.182819
3.998347 2.194714
4.266880 2.160797
4.344415 2.154483
4.714916 2.141987
4.798001 2.135526
4.965595 1.871750
5.199670 1.789360
5.334784 1.386364
5.574860 1.413061
5.858532 1.056488
exmaple:
v0=(np.loadtxt(«vehicleOutline/vehicleOutline0.txt»,dtype=float,delimiter=’ ‘) * 1000).astype(np.int32)
2.then reshape to (length,1,2),excute the function computeDistance

example:
sd=cv2.createShapeContextDistanceExtractor()
a0 = arr[i].reshape(arr[i].shape[0],1,2)
a1 = arr[j].reshape(arr[j].shape[0],1,2)
print(i,»match»,j,»=»,sd.computeDistance(a0,a1))

3.result:
some of txt files went success,but others went wrong.top the data went wrong,i dont know how to slove it.

The text was updated successfully, but these errors were encountered:

Источник

matrix_expressions.cpp:24: error: (-5:Bad argument) Matrix operand is an empty matrix. in function ‘cv::checkOperandsExist’ #18572

environment:
OpenCV(4.3.0)
language:python 3.6

1.load the data from txt files,and then convert type from float to int32.
a.txt
4.020161 0.372046
4.086024 0.548271
4.112598 0.539363
4.162546 0.522878
4.252789 0.684608
4.265030 0.681673
4.572025 0.757398
4.752093 0.743017
4.958206 0.821787
5.138208 0.807434
5.298540 0.906368
5.542401 0.878399
5.798231 1.013368
6.018507 1.075400
6.113993 1.135273
6.425354 1.265514
6.545009 1.264395
6.731231 1.205198
6.901707 1.293404
7.236600 1.293581
7.264717 1.276446
7.542284 1.294016
7.849143 1.123871
7.888957 0.818015

b.txt
0.558444 0.486612
0.590397 0.479795
0.637800 0.728716
0.688097 0.927678
0.911380 1.735989
0.946417 1.752804
1.247624 2.280543
1.341965 2.214138
1.552272 2.264075
1.891904 2.235193
1.943452 2.234293
2.129528 2.216326
2.370298 2.131144
2.654617 2.204402
2.769804 2.168312
2.967309 2.118495
3.258043 2.180414
3.386168 2.172515
3.582158 2.205668
3.909915 2.182819
3.998347 2.194714
4.266880 2.160797
4.344415 2.154483
4.714916 2.141987
4.798001 2.135526
4.965595 1.871750
5.199670 1.789360
5.334784 1.386364
5.574860 1.413061
5.858532 1.056488
exmaple:
v0=(np.loadtxt(«vehicleOutline/vehicleOutline0.txt»,dtype=float,delimiter=’ ‘) * 1000).astype(np.int32)
2.then reshape to (length,1,2),excute the function computeDistance

example:
sd=cv2.createShapeContextDistanceExtractor()
a0 = arr[i].reshape(arr[i].shape[0],1,2)
a1 = arr[j].reshape(arr[j].shape[0],1,2)
print(i,»match»,j,»=»,sd.computeDistance(a0,a1))

3.result:
some of txt files went success,but others went wrong.top the data went wrong,i dont know how to slove it.

The text was updated successfully, but these errors were encountered:

Источник

Opencv loads models of dynamic input types #19347

Actual error message (3.4.17/4.5.5+): DNN/ONNX(Shape): dynamic ‘zero’ shapes are not supported

  • OpenCV => 4.5.1
  • Operating System / Platform => Windows 64 Bit
  • Compiler => MinGW 7.3

Can opencv load dynamic input models?

An error is reported when using opencv to load the onnx model of dynamic input type.

Detailed description

The following is the compressed package of the input type and model file.

After I converted a pytorch model to onnx, the input size was 1x3x640x640. This model can run at onnxronnuntime. Then I tried to use opencv’s readNet(path) function. The model can also work normally.

When I convert this model to dynamic input, this model can also run in onnxronnuntime, but when I use opencv’s readNet to load this dynamic input model, ,the program starts to report an error, the error is as follows

OpenCV: terminate handler is called! The last OpenCV error is: OpenCV(4.5.1) Error: Assertion failed (total(os[i]) > 0) in getLayerShapesRecursively, file F:OpenCVopencv451sourcesmodulesdnnsrcdnn.cpp, line 3520

If opencv can load dynamic input models,do I need to set the input and output size after the model is loaded by opencv?
If yes, is there any information on this part of the content?

Steps to reproduce

I first use python to convert the model to onnx.
The conversion code of pytorch to onnx I used is as follows

Then use opencv to load, the key code is as follows

Issue submission checklist
  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

The text was updated successfully, but these errors were encountered:

Источник

import Tensorflow 2.x PB via readNetFromTensorflow DNN api function (C++) #16879

I have a UNet DNN that I have created and trained in python (TF2.1/Keras). I saved the model to a PB file using the Model.save() method. Reloading the model via the Model.load_file() method in TF works fine, but I cannot load the model using readNetFromTensorflow() in OpenCV. I hear SavedModel is not currently supported by OpenCV, and that I should use a frozen graph, but frozen graph functionality is deprecated in TF2.x. Any solutions here?
Thanks,
Rob

System information (version)
  • OpenCV => 4.2
  • Tensorflow => 2.1
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2019

The text was updated successfully, but these errors were encountered:

Hi! Please add a link to specific model.

Maybe it would save time if I debugged this myself. Is there a known-good TF2.1/Keras model that has been loaded in opencv using the DNN API? Like a tutorial TF2.1 model? I am looking for one right now.
Thanks,
Rob

I used the following test code to generate and store a TF2.1 model under mnist_test (called saved_model.pb):

In a C++ app, I try to load the saved_model.pb file with the following code:

(pbPath is «models/saved_model.pb’»

The error I get is fairly consistent:

[libprotobuf ERROR C:opencv4.2.0opencv-4.2.03rdpartyprotobufsrcgoogleprotobufwire_format_lite.cc:629] String field ‘opencv_tensorflow.FunctionDef.Node.ret’ contains invalid UTF-8 data when parsing a protocol buffer. Use the ‘bytes’ type if you intend to send raw bytes.
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.2.0) Error: Unspecified error (FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse GraphDef file: C:DATADeveloperDeepLearningSemantic_Segmentationunetmodelsmnist_testsaved_model.pb) in cv::dnn::ReadTFNetParamsFromBinaryFileOrDie, file C:opencv4.2.0opencv-4.2.0modulesdnnsrctensorflowtf_io.cpp, line 42

@rtrahms, may I ask you to try the following approach? It’s the first time we are trying it so need your feedback:

  1. I changed input resolution from 1x28x28 to 1x28x28x1 (NHWC)
  2. Used the following script to convert SavedModel to a frozen graph:
  1. Tried to run with the following script:

(note that input for OpenCV should be NCHW).

Update: with changes from #16905 it’s enough to just use

@dkurt **I followed the code mentioned by you. Can you help me?

I am using Tensorflow-GPU 2.4.0.

I have the following error**

TypeError: signature_wrapper(*, input_tensor) missing required arguments: input_tensor

The whole trace is as follows

Источник

I am trying to create a vec file from my positive image samples. I’m using the latest version of Opencv. The command I am using is this:

opencv_createsamples -info Positive.info -num 3750 -w 24 -h 24 -vec Positive.vec

All my images are bigger than 24×24, so I don’t believe that that is the issue. I’ve tried searching online, but I don’t find anyone with this error while doing the createsamples command. The output that I get when I run that is this:

Info file name: Positive.info
Img file name: (NULL)
Vec file name: Positive.vec
BG  file name: (NULL)
Num: 3750
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 24
Height: 24
Max Scale: -1
RNG Seed: 12345
Create training samples from images collection...
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.0.0-alpha) Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file c:buildmaster_winpack-build-win64-vc15opencvmodulescoresrcmatrix.cpp, line 465

This is my first time using opencv, so I’m very unclear as to what this error is. Anyone have any experience with this or can point me in the right direction to correcting the error?

Edit: Here is the first few lines of my Positive.info file:

full_pathpositives7bc1acac12bbc9876db252efc0249c5863c9de9b620eb8745c5d1202.jpg 1 54 54 362 362 
full_pathpositivesc1705114e4e13be2b0a8d4a214d59bbd7d8427cc7adadd3811712cd0.jpg 1 275 275 1835 1835
 full_pathpositivesd103070d5cf33bd0b51f47dc2116ffdb764fba589b715858ca6415b6.png 1 36 36 351 351 
full_pathpositives8789913eb072be66371cedf7bf6ec1ce08780923e84847006730508e.jpg 1 42 42 282 282 
full_pathpositivesb12785be8686004a39b9a32a2c0af56c75e650a8b93785979d797b2c.jpg 1 45 45 300 300 
full_pathpositivesbef84d8d43a9fb5f119ca7e94863fd16a3e92206414e68bd18607b49.jpg 1 22 22 152 152 
full_pathpositiveseef8e58c523263dc2371a899fa80686d50362e803e6c1d4b0c718cf1.jpg 1 41 41 275 275 
full_pathpositivesdf236ca99ff5e618a971bee4599e16672b5ded618c8b77a3b2a90216.jpg 1 75 75 501 501

The path to the files is correct.

Recommend Projects

  • React photo

    React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo

    Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo

    Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo

    TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo

    Django

    The Web framework for perfectionists with deadlines.

  • Laravel photo

    Laravel

    A PHP framework for web artisans

  • D3 photo

    D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Visualization

    Some thing interesting about visualization, use data art

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo

    Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo

    Microsoft

    Open source projects and samples from Microsoft.

  • Google photo

    Google

    Google ❤️ Open Source for everyone.

  • Alibaba photo

    Alibaba

    Alibaba Open Source for everyone

  • D3 photo

    D3

    Data-Driven Documents codes.

  • Tencent photo

    Tencent

    China tencent open source team.

Вот рабочий код без Qt, который решает мою задачу:

Mat image;
image = imread("C:\mel.bmp",1);


Mat gray, edqes, out;
cvtColor(image, gray, COLOR_BGR2GRAY);
Canny(gray, edqes, 50, 150, 3);
cvtColor(edqes, edqes, COLOR_GRAY2BGR);
bitwise_or(edqes,image,out);


cvNamedWindow("original",CV_WINDOW_NORMAL);
cvNamedWindow("binary",CV_WINDOW_NORMAL);
cvNamedWindow("canny",CV_WINDOW_NORMAL);
cvNamedWindow("out",CV_WINDOW_NORMAL);

imshow("original",image);
imshow("binary", gray);
imshow("canny", edqes);
imshow("out", out);

Я собираюсь использовать его с Qt, чтобы отобразить на QGraphicsView. Вот этот код я для этого использую:

QImage temp = nPixDst->pixmap().toImage();

cv::Mat image = QImage2Mat(temp) ;

int niz = ui->lin_bot->text().toInt();
int verh = ui->lin_top->text().toInt();

Mat gray, edqes, out;
cvtColor(image, gray, COLOR_BGR2GRAY);
Canny(gray, edqes, niz, verh, 3);
cvtColor(edqes, edqes, COLOR_GRAY2BGR);
bitwise_or(edqes,image,out);

nPixDst->setPixmap( QPixmap::fromImage( Mat2QImage( out )) );

но я получаю следующую ошибку:

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.9) Error: Sizes of input arguments do not match (The
operation is neither ‘array op array’ (where arrays have the same size
and type), nor ‘array op scalar’, nor ‘scalar op array’) in
cv::binary_op, file
E:softbuildopencvopencv-srcmodulescoresrcarithm.cpp, line 229

как это можно исправить?

вот этот код я использую для конвертирования из QImage в Mat и обратно:

QImage MainWindow::Mat2QImage(cv::Mat const& src)
{
    switch(src.type())
    {
    case CV_8UC4:
    {
        cv::Mat view(src);
        QImage view2(view.data, view.cols, view.rows, view.step[0], QImage::Format_ARGB32);
        return view2.copy();
        break;
    }
    case CV_8UC3:
    {
        cv::Mat mat;
        cvtColor(src, mat, cv::COLOR_BGR2BGRA); //COLOR_BGR2RGB doesn't behave so use RGBA
        QImage view(mat.data, mat.cols, mat.rows, mat.step[0], QImage::Format_ARGB32);
        return view.copy();
        break;
    }
    case CV_8UC1:
    {
        cv::Mat mat;
        cvtColor(src, mat, cv::COLOR_GRAY2BGRA);
        QImage view(mat.data, mat.cols, mat.rows, mat.step[0], QImage::Format_ARGB32);
        return view.copy();
        break;
    }
    default:
    {
        //throw invalid_argument("Image format not supported");
        return QImage();
        break;
    }
    }
}

cv::Mat MainWindow::QImage2Mat(QImage const& src)
{
    switch(src.format()) {
    case QImage::Format_Invalid:
    {
        cv::Mat empty ;
        return empty  ;
        break;
    }
    case QImage::Format_RGB32:
    {
        cv::Mat view(src.height(),src.width(),CV_8UC4,(void *)src.constBits(),src.bytesPerLine()) ;
        return view ;
        break;
    }
    case QImage::Format_RGB888:
    {
        cv::Mat out ;
        cv::Mat view(src.height(),src.width(),CV_8UC3,(void *)src.constBits(),src.bytesPerLine());
        cv::cvtColor(view, out, cv::COLOR_RGB2BGR);
        return out ;
        break;
    }
    default:
    {
        QImage conv = src.convertToFormat(QImage::Format_ARGB32);
        cv::Mat view(conv.height(),conv.width(),CV_8UC4,(void *)conv.constBits(),conv.bytesPerLine());
        return view ;
        break;
    }
    }
}

System information (version)
  • OpenCV => 4.5.4
  • Operating System / Platform => Windows 64 bit
  • Compiler => MinGW g++
Detailed description

The recoverPose() function does not work using any cameraMatrix, while it does work using a single focal point value and principal point. The assertion that fails is the case that cameraMatrix.rows == 3 && cameraMatrix.cols == 3 && cameraMatrix.channels() == 1, however all of these are true.

Steps to reproduce
  1. Get cameraMatrix values (e.g. cv::Mat::eye(3, 3, CV_64FC1)). I found this bug using a camera matrix generated by calibrateCamera() that throws the same assertion, so Mat::eye() is not the issue.
  2. Detect features between two frames
  3. Use findEssentialMat (does NOT fail assertion)
  4. Use recoverPose (fails assertion unlike findEssentialMat)

Code example:

#include <opencv2/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc/Imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/video/tracking.hpp>
#include <opencv2/calib3d.hpp>
#include <iostream>

using namespace cv;

int main() {
    // Get two frames
    Mat frame1 = imread("frame1.jpg", IMREAD_COLOR);
    Mat frame2 = imread("frame2.jpg", IMREAD_COLOR);
    Mat gray1; cvtColor(frame1, gray1, COLOR_BGR2GRAY);
    Mat gray2; cvtColor(frame2, gray2, COLOR_BGR2GRAY);

    // Get features
    std::vector<Point2f> pointsOfFirstFrame, pointsOfSecondFrame;
    std::vector<KeyPoint> keypoints_1, key2;
    FAST(gray1, keypoints_1, 20, false);
    KeyPoint::convert(keypoints_1, pointsOfFirstFrame, std::vector<int>());

    // Track features
    std::vector<float> err;	
    std::vector<uchar> status;				
    Size winSize=Size(21,21);																								
    TermCriteria termcrit=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01);

    calcOpticalFlowPyrLK(gray1, gray2, pointsOfFirstFrame, pointsOfSecondFrame, status, err, winSize, 3, termcrit, 0, 0.001);

    // getting rid of points for which the KLT tracking failed or those who have gone outside the frame
    int indexCorrection = 0;
    for( int i=0; i<status.size(); i++) { 
        Point2f pt = pointsOfSecondFrame.at(i- indexCorrection);
        if ((status.at(i) == 0)||(pt.x<0)||(pt.y<0))	{
            if((pt.x<0)||(pt.y<0))	{
                status.at(i) = 0;
            }
            pointsOfFirstFrame.erase (pointsOfFirstFrame.begin() + (i - indexCorrection));
            pointsOfSecondFrame.erase (pointsOfSecondFrame.begin() + (i - indexCorrection));
            indexCorrection++;
        }
    }

    // Find essential matrix (Does NOT fail assertion)
    Mat E, R, t, mask;
    Mat cameraMatrix = Mat::eye(3, 3, CV_64FC1);
    std::cout << "Camera matrix: n" << cameraMatrix << 'n';
    std::cout << "Rows: " << cameraMatrix.rows << " Cols: " << cameraMatrix.cols << " Channels: " << cameraMatrix.channels() << 'n';
    E = findEssentialMat(pointsOfSecondFrame, pointsOfFirstFrame, cameraMatrix, RANSAC, 0.999, 1.0, mask);
    std::cout << "findEssentialMat() assertions passed.n";

    // Find pose (Unlike findEssentialMat, fails assertion)
    recoverPose(E, pointsOfSecondFrame, pointsOfFirstFrame, R, t, cameraMatrix, mask);

    std::cout << "All assertions passed";
}

output:

Camera matrix: 
[1, 0, 0;
 0, 1, 0;
 0, 0, 1]
Rows: 3 Cols: 3 Channels: 1
findEssentialMat() assertions passed.
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.5.4) Error: Assertion failed (cameraMatrix.rows == 3 && cameraMatrix.cols == 3 && cameraMatrix.channels() == 1) in recoverPose, file C:Usersdps1Downloadsopencv-4.5.4modulescalib3dsrcfive-point.cpp, 
line 574

Images used:
images.zip

Issue submission checklist
  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution

  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Opencv error cannot load info library for opencv
  • Opencv error 215 assertion failed
  • Opencl kernel build error 11
  • Opencl error 1001
  • Opencl dll error 126

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии