Error parsing onnx model while trying to use YOLOv5 - c++

I want to use YOLOv5 for object detection Using C++ and OpenCV's DNN. I'm using Windows 10, and VS 2019.
However, the following line of code:
#include <opencv2/opencv.hpp>
int main(int, char **)
{
auto net = cv::dnn::readNet("yolov5s.onnx");
return 0;
}
causes the following error:
OpenCV(4.1.1) C:\opencv-4.1.1\modules\dnn\src\onnx\onnx_importer.cpp:57: error: (-210:Unsupported format or combination of formats) Failed to parse onnx model in function 'cv::dnn::dnn4_v20190621::ONNXImporter::ONNXImporter'
Press any key to continue . . .
This is a link to the original .pt file that I downloaded from the Yolov5 repository, and this is a link to the .onnx file that I converted as per the instructions.
Edit:
Seems there was a problem with the path.
After I wrote the full path to the full .onnx file path, as follows:
#include <opencv2/opencv.hpp>
int main(int, char **)
{
auto net = cv::dnn::readNet("C:/Users/hedey/source/repos/Road_Defects_Detector/yolov5s.onnx");
return 0;
}
Now, I'm getting the following error:
OpenCV(4.1.1) C:\opencv-4.1.1\modules\dnn\src\onnx\onnx_importer.cpp:320: error: (-204:Requested object was not found) Blob not found in const blobs in function 'cv::dnn::dnn4_v20190621::ONNXImporter::getBlob'
Press any key to continue . . .

Related

cv::imread and other does not working with emscripten?

I have following C++ code with opencv. It is basic code for display image.
I'm trying to compile it using emscripten but it seems that emscripten can't load some function of opencv. For example the cv::Mat is ok.
Test for build_js went all right.
Do you know what I'm doing wrong?
Code:
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <emscripten/emscripten.h>
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
cv::Mat image;
image = cv::imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
cv::namedWindow("Display Image");
cv::imshow("Display Image", image);
cv::waitKey(0);
return 0;
}
Error message:
/home/vasek/project_test/opencv/opencvgcccmake_emscript/DisplayImage.cpp:15:13: error: use of undeclared identifier 'imread'
image = cv::imread( argv[1], 1 );
^
/home/vasek/project_test/opencv/opencvgcccmake_emscript/DisplayImage.cpp:21:9: error: no member named 'namedWindow' in namespace 'cv'
cv::namedWindow("Display Image");
~~~~^
/home/vasek/project_test/opencv/opencvgcccmake_emscript/DisplayImage.cpp:22:9: error: no member named 'imshow' in namespace 'cv'
cv::imshow("Display Image", image);
~~~~^
/home/vasek/project_test/opencv/opencvgcccmake_emscript/DisplayImage.cpp:23:9: error: no member named 'waitKey' in namespace 'cv'
cv::waitKey(0);
~~~~^
4 errors generated.
cmake command:
emcmake cmake -DOpenCV_DIR=/home/vasek/tools/opencv/build_js ..
Edit:
None of the function work exept cv::Mat.
This is not a problem with includes, since opencv2/opencv.hpp automagically pulls in all the module top-level headers if the modules are available. The obvious conclusion is that those modules are not available in your build of OpenCV, and now the question is why is that the case?
As it turns out, some of the OpenCV functionality is not suitable for Web, and opencv.js is built without it.
The functions cv::namedWindow, cv::imshow and cv::waitKey belong to the highgui module. The implementation of this module is platform-dependent (at build time you have to select the backend that will be used, be it WinAPI, WinRT, Gtk, Qt, cocoa, etc.). Furthermore, since (AFAIK) the JavaScript code in the browser runs in a sandbox, it would be impossible to access to APIs anyway.
The function cv::imread belongs to the imgcodecs module, yet another one that is not built in this case. I don't know the exact reason for this (perhaps due to some of it directly accessing filesystem), and the issue https://github.com/opencv/opencv/issues/17535 indicates that the third party codecs haven't been integrated into opencv.js and some mechanisms are missing from the binding generator.

Cannot create FisherFaceRecognizer with OpenCV 4 (C++)

I'm following an older tutorial on face recognition based on OpenCV in C++ and have an error I can't resolve. The relevant code snippet:
#include "opencv2/core/core.hpp"
#include "opencv2/face.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
...
Ptr<face::FaceRecognizer> model = face::createFisherFaceRecognizer();
model->train(images, labels);
...
I have my OpenCV compiled correctly with contrib modules, have them included but it still gives the error:
error: 'createFisherFaceRecognizer()' is not a member of 'cv::face'
I also trief this one:
Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer_create();
error: 'FisherFaceRecognizer_create()' is not a member of 'cv::face'
I looked up the face.hpp, ad the class has a function 'create', so I tried to use it, but this also failed:
Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer.create();
error: expected primary-expression before '.' token
which is weird since the function has parameters with default values. All the online solutions I treid failed. What was changed in the newer OpenCV versions and how can I create a face recognizer object correctly?
According to the official document,
Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components=0, double threshold=DBL_MAX)
is used openCV2. Since you use openCV 4, you have to follow the documentation that works with openCV 4.
Try this:
static Ptr<FisherFaceRecognizer> cv::face::FisherFaceRecognizer::create (int num_components = 0, double threshold = DBL_MAX )
On the top of this page, you can adjust the version of openCV library which you have.

Node symbol lookup error opencv

I am currently writing a C++ module for node that uses open cv, and I encountered an issue that I do not quite understand. Basically this is the method that I am trying to add
void GetPuzzle(const Nan::FunctionCallbackInfo<v8::Value>& args) {
v8::String::Utf8Value parameter(args[0]->ToString());
std::string filePath = std::string(*parameter);
Mat puzzle = imread("sudoku.jpg", 0);
}
Just to make sure that the included open cv is working properly. node-gyp build works, exits with an ok , however when I am actually running the server.js file I get the following exception :
node: symbol lookup error: /home/dave/Projects/puzzlesolver/build/Release/sudokuGrabber.node: undefined symbol: _ZN2cv6imreadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
This is the include of the opencv :
#include <opencv2/opencv.hpp>
I guess this info is important for solving the issue - I am working on linux (ubuntu). Any suggestion of what is wrong with my code and what could I do to fix it ?

Code::Blocks, c++, magick++ any demo results in: mingw32-g++.exe: fatal error: no input files

I am trying to use Magick++ with Code::Blocks (both are latest versions).
I use win7 x64 and I installed both ImageMagick x86 and x64 dynamic (with DLLs).
Every time I try to run a demo c++ file (like the code below,) I get the same message:
\ImageMagick-6.8.6-Q16\include\" -c C:\Users\ad\Desktop\C++\Magick++\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe: fatal error: no input files
compilation terminated.
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
does anybody has experienced this?
Could you help me to make it work?
I put a .jpg file "wall.jpg" in the same folder as the project.
Thanks
Source code from the magick++ demo folder
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
InitializeMagick(*argv);
// Construct the image object. Seperating image construction from the
// the read operation ensures that a failure to read the image file
// doesn't render the image object useless.
Image image;
try {
// Read a file into image object
image.read( "wall.jpg" );
// Crop the image to specified size (width, height, xOffset, yOffset)
image.crop( Geometry(100,100, 100, 100) );
// Write the image to a file
image.write( "x.gif" );
}
catch( Exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}
may be your input path is error set or your account don't have privilege to read the file in "C:\Users\ad\Desktop\C++\Magick++\test\main.cpp",check it and try again
Hello ,
the problem is not the missing "wall.jpg",
but the compilation process (creating the executable binary) , as your example output shows :
mingw32-g++.exe: fatal error: no input files
To find out what is going wrong, you should post the command you run
and the complete error output.
Best,
Jack
I think the error happened in the first sentence of main:InitializeMagick(*argv), you can debug into this calling, may be it's caused by the NULL pointer of argv.
Oh, no, the project didn't even compile! (see the error msg)
I think you should revise the way you used to create your project. Personally, i double checked how to create a project and luckily worked.

OpenCV problems.

I'm new here and I've been trying to set up OpenCV on my codeblocks IDE. I'm not sure whats wrong. I'm using windows 7, 64bit system, and codeblocks, I also downloaded 2-4.3 version of OpenCV.
I tried following the manual intsructions here, but that was of no help: http://opencv.willowgarage.com/wiki/CodeBlocks
Even though I'm trying to use codeblocks I also tried:
Installing OpenCV 2.4.3 in Visual C++ 2010 Express
I have my path set to:
C:\OpenCV\build\x64\vc10\bin
And for the compiler settings under tab "search directories":
"Compiler" : C:\OpenCV\build\include
"Linker" : C:\OpenCV\build\x64\vc10\lib
And then under the tab "Linker settings" I have all the .lib files from
C:\OpenCV\build\x64\vc10\lib
I tried running this as my test program and it gives me an error readout connecting to
operations.hpp header file:
#include "opencv2/highgui/highgui.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main()
{
Mat im = imread("c:/full/path/to/lena.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
The error says:
C:\OpenCV\build\include\opencv2\core\operations.hpp|3915|error: expected primary-expression before '>' token|
C:\OpenCV\build\include\opencv2\core\operations.hpp|3915|error: expected primary-expression before ')' token|
....and a bunch of other stuff, but those are the first 2 errors.
So my 2 fold question is this:
1) Did I set up my IDE correctly?
2) Is there something wrong with the OpenCV code?
The solution of this problem is to edit the line 3915 of operations.cpp file. The correct return argument is
return _create(name).Ptr<_Tp>();
have you tried include opencv core?
#include "opencv2/core/core.hpp"
my assumption is you don't use the core function, so your code not recognize some function.