Error using Caffe: "This tool requires OpenCV; compile with USE_OPENCV." - opencv

I want to use Caffe's tool, compute_image_mean to compute the mean image, but the command line tells me that:
This tool requires OpenCV; compile with USE_OPENCV.
I've searched the Internet, and one guy said:
Well, this message suggests that you have compiled caffe without
OpenCV, i.e; with USE_OPENCV set to 0 in your Makefile.config.
Recompile with that settings commented out (as is the default) and try
again. And of course you need to have OpenCV installed for this to
work.
But I have already set USE_OPENCV := 0 when I compiled my Caffe.
Could someone help me to solve this problem?

I think you have misread the statement you found, it says you are compiling without OpenCV, which means WITH_OPENCV := 0 , to compile Caffe with OpenCV you have to set WITH_OPENCV := 1 , or just comment it out.

I met the same error information when I used caffe to do my work. I solved this problem by modifying something in the "Makefile.config" file.
The same as the lastest answer, I commented this line "USE_OPENCV := 0" with "#", so after compiling I can use OpenCV's function. I can use this way to deal with it, but you said that when you did this action and got another error. I think you didn't install your OpenCV correctly. Maybe it's your version problem or environment variable error. You can try to install OpneCV again.

I met the same error when I tried to make lmdb.
At first I uncomment "USE_OPENCV:=0" in the Makefile.config and recompile for many times, but it does not help.
So I try to comment "USE_OPENCV:=0" with # and recompile the caffe, it success.

Related

Gsteamer conflicting declaration in opencv in Yocto build

I am building Yocto 2.5(Sumo) with Gstreamer 1.14 and OpenCV 3.4.5
I am getting this error while compiling Gstreamer:
build_xwayland_mq/tmp/work/aarch64-mx8m-poky-linux/gstreamer1.0-plugins-bad/1.14.4.imx-r0/recipe-sysroot/usr/include/opencv2/imgproc/types_c.h:445:21: error: conflicting declaration of C function 'CvMoments cvMoments(const cv::Moments&)'
CV_INLINE CvMoments cvMoments(const cv::Moments& m)
same error in imgproc_c.h:360:13
I saw someone solved this by building with OpenCV 4 instead, but we need OpenCV 3.4.5 for our own project.
Anyone know how to resolve this conflict?
too long for comment..
I did just quick search, found this:
https://www.yoctoproject.org/pipermail/meta-freescale/2019-March/023888.html
There is some problem in includes .. I guess in mentioned hpp files there are some types that are not declared in that imgproc_c.h for 3.4, but already are moved there for opencv 4 (just my guess).
You just need to add those hpp on all places (in gst plugins bad) where you find include for imgproc_c.h.
Take inspiration from this.. or maybe it itself will solve your issue:
https://git.yoctoproject.org/cgit/cgit.cgi/meta-freescale/tree/recipes-multimedia/gstreamer/gstreamer1.0-plugins-bad/0001-opencv-fix-build-for-opencv-3-4-2.patch?h=thud
The patch is for yocto thud.. but perhaps it does not matter for GStreamer.
In worst case you will have to backport it or make your own patch for sumo.
Or if you can try update to thud (should be small difference) or newer and check if it persists.

Cant' build OpenCV 3.2.0 (Mingw32)

I know... Another one of this... But no one else's error is the same as mine and I've been trying to build opencv with mingw32 for days now.
When building OpenCV with mingw the command mingw32-make fails at some point trying to compile sources\modules\ts\src\ts_gtest.cpp with error pic bellow:
I've tried following several tutorials, but none work cleanly and this is the best I could get stuff to work.
What I did:
Installed Mingw and added C:\Mingw\bin\ to PATH environment variable.
Installed CMake and added it too to PATH.
Extracted OpenCV to C:\ and created forlder C:\opencv\mingwBuild\
In CMake-GUI I define source folder as C:\opencv\sources\ and build folder as C:\opencv\mingwBuild\.
Hit Configure and select Mingw Makefiles, with 'Use default native compilers' (have also specified compilers explicitly and the result is the same.).
Hit Generate, which creates the Makefile.
I open C:\Mingw\msys\1.0\msys.bat to have a console with all variables loaded (have also tried directly from a simple cmd.exe, given that PATH is set for mingw, but I get the same error in compilation). Navigate to C:\opencv\mingwBuild\ and run mingw32-make.
And that's where the error shows up after a while. Any ideas?
Turns ou gTest was not compiling in Mingw for some reason.
As I don't intend to test my code (for now) I removed opencv_ts from instalation (by deselecting it in Cmake, after configuring and before generating).
Someone mentions, in the first link #Dan Masek refers, that GTest has this issue with type conversion under mingw. They say that you can edit ts_gtest.cpp to apply the correct conversion, according to error message. That may be a solution if you need this module.
Another comment in #Dan Masek's second link mentions that gcc's version 5 surpasses the issue, which version 4 has. So, getting a hold of such distro may also be a solution.
For me it seems to be fixed by applying this fix: https://github.com/msk-repo01/opencv/commit/9a1835ce6676836ce278d723da4ff55a8f900ff1
(Also see: https://github.com/opencv/opencv/issues/8105)
The fix basically replaces the "_RTL_CRITICAL_SECTION" by "_CRITICAL_SECTION" for MingW compilers in modules/ts/include/opencv2/ts/ts_gtest.h in the following way:
The lines
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
struct _RTL_CRITICAL_SECTION;
(around line 723 in OpenCV 3.2.0 release from Dec. 2016) are replaced by
# if GTEST_OS_WINDOWS_MINGW
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# else
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# endif
and
_RTL_CRITICAL_SECTION* critical_section_;
is replaced by
GTEST_CRITICAL_SECTION* critical_section_;

Rejecting re-init on previously failed class error when loading a Class with dalvikvm

I am trying to use Terminal IDE on Lollipop 5.1.1. Using a Samsung E7 device, a mod version of Terminal IDE is provided by someone on XDA
here:
http://forum.xda-developers.com/showthread.php?t=1340852&page=7
I tried to use javac script in that mod but it gave an unsatisfied link error, saying that:
$ javac
java.lang.UnsatisfiedLinkError: org.apache.harmony.security.fortress.Services
at org.apache.harmony.security.fortress.Engine.getServices(Engine.java:158)
at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:137)
at java.security.cert.CertificateFactory.getInstance(CertificateFactory.java:90)
at
org.apache.harmony.security.utils.JarUtils.verifySignature(JarUtils.java:83)
at java.util.jar.JarVerifier.verifyCertificate(JarVerifier.java:294)
at java.util.jar.JarVerifier.readCertificates(JarVerifier.java:268)
at java.util.jar.JarFile.getInputStream(JarFile.java:380)
at libcore.net.url.JarURLConnectionImpl.getInputStream(JarURLConnectionImpl.java:222)
at java.net.URL.openStream(URL.java:470)
at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:444)
at java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:515)
at java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:542)
at java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:542)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:228)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:139)
at com.sun.tools.javac.main.JavaCompiler.version(JavaCompiler.java:112)
at com.sun.tools.javac.main.JavaCompiler.version(JavaCompiler.java:97)
at com.sun.tools.javac.main.Main.bugMessage(Main.java:434)
at com.sun.tools.javac.main.Main.compile(Main.java:421)
at com.sun.tools.javac.main.Main.compile(Main.java:308)
at com.sun.tools.javac.main.Main.compile(Main.java:299)
at com.sun.tools.javac.Main.compile(Main.java:82)
at com.spartacusrex.spartacuside.external.javac.main(javac.java:13)
$
It is strange that there is a UnsatisfiedLinkError , because it doesn't say that VM cannot find xyz.so library or cannot find xyz method.
I tried using logcat command right after using Terminal IDE's javac script on Device, the odd thing I found from there is :
I/art ( 6558) : rejecting re-init on previously-failed class java.lang.Class<org.apache.harmony.security.fortress.Services>
I couldn't understand why this happened,
The javac script uses android's dalvikvm command to load
com.spartacusrex.spartacuside.external.javac
class. People have faced this rejecting re-init issue on sdk version 20+ but it's not clear to me why this info message uccurs and how to solve it.
I copied /system/lib/libjavacrypto.so to Terminal IDE's ~/system/lib folder and now javac and dx tools are working.
It seems like Google messed up with things in /system/lib which resulted in errors.
Answering so someone else might find it useful.

How to setup jpeglib with MS Visual C++ 2010 Express

I try to use the well known "jpeglib" now available in version 9.
Overview: I am a programming starter in C using MS Visual C++ 2010 Express and read a C-book finally. My goal is to compress a RGB(.bmp)-file into JPEG. So I downloaded the jpeglib (v9), read all the install and so on *.txt-files. It was possible to compile the C-files to get cjpeg.exe, djpeg.exe, jpeg.lib and so on.
After this success I tried to use the example.c to get deeper into the jpeg and to control the compression. -> It did not work. Then I tried to use the jpeglib included in OpenCV. Same non working result, while the OpenCV code samples are compiled successfully.
I googled lots of samples, problem solutions and tips how to use jpeglib. Most helpful information I found here. But in the result I was still not able to compile my own jpeg-tool or example.c (rewriting the write_JPEG_file() function ).
Question: What in the basics could be wrong, when every other programmer just uses #include "jpeglib.h" in their codes to run the jpeg functions successfully? For me including this file seems not to be enough. Because of that I have to ask you and to relaunch a one year old Question that also did not helped solving my probs. I can not give you a specific error message because of multiple attempts to solve those issues.
Here is my current MS-VC++2010 config for using OpenCV 2.4.6:
C/C++ -> General -> Additional Include Directories:
C:\opencv\build\include
C:\opencv\build\include\opencv
C:\opencv\build\include\opencv2
C:\opencv\include
C:\opencv\include\opencv
C:\opencv\include\opencv2
C:\opencv\3rdparty\libjpeg
Linker -> General -> Additional Library Directories:
C:\opencv\build\x86\vc10\lib
Linker -> Input -> Additional Dependencies:
opencv_core246d.lib
opencv_imgproc246d.lib
opencv_highgui246d.lib
opencv_ml246d.lib
opencv_video246d.lib
opencv_features2d246d.lib
opencv_calib3d246d.lib
opencv_objdetect246d.lib
opencv_contrib246d.lib
opencv_legacy246d.lib
opencv_flann246d.lib
jpeg.lib [this I added into C:\opencv\build\x86\vc10\lib]
At last some threads I have already read:
Compressing IplImage to JPEG using libjpeg in OpenCV - 1
Compressing IplImage to JPEG using libjpeg in OpenCV - 2
Need help in reading JPEG file using libjpeg
how can i use jpeg_mem_src, jpeg_mem_dest in libjpeg-turbo?
If there is something missing you want to know I will do my best to add this information!
EDIT - Some error messages:
1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""unsigned char * image_buffer" (?image_buffer##3PAEA)".
1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""int image_height" (?image_height##3HA)".
1>jpeg_coder.obj : error LNK2001: unresolved external symbol """int image_width" (?image_width##3HA)".
First symbol should be typedefed in jpeglib.h as JSAMPLE FAR *JSAMPROW,
second and third are defined in rdjpgcom.c as unsigned int image_height, image_width;
Maybe, with a lot of luck, I figured out what is need to be done to get jpeglib running. In the current state I have to check and double check whether my problem solution is correct or not. At this point thank you very much for your attention for my issues. As soon as I am sure with the solution I will post it.
Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file. The proper file for linking is libjpegd.lib. Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. For now the problem is solved.
Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file.
The proper file for linking is libjpegd.lib.
Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. Thanks to all who tried solving this issue. For now the problem is solved.

Simple OpenCV problem

Why I try to run the following OpenCV program, it shows the following error :
ERROR:
test_1.exe - Application Error
The application failed to initialize properly (0x80000003).
Click on OK to terminate the application.
CODE:
#include "cv.h"
#include "highgui.h"
int main()
{
IplImage *img = cvLoadImage("C:\\face.bmp");
cvSetImageROI(img, cvRect(100,100, 100, 100));
cvAddS(img, cvScalar(50), img);
cvResetImageROI(img);
cvShowImage("Test", img);
cvWaitKey(0);
return 0;
}
When i press F5(im using vs2008express), the program encounters a break point...i have attached a picture...dont know, whether, it will help or not.
Error Snapshot Link
It is not that, only this program is producing this error, but also any kind of image manipulation funciton containing (OpenCV)program is resulting in this sitution.
Such as : cvSmooth
one last thing, it there any dedicated OpenCV forum or sth like that?
I am an administrator.So, yes, ive the permission.
a version mismatch.
sorry, i didn't get it?Version mismatch with what?
But, i have found the error using dependency walker.
Warning: At least one module has an unresolved import due to a missing export
function in a delay-load dependent module.
and also found that, it is a common problem, and found some info in the FAQ of DW...
Why am I seeing a lot of applications where MPR.DLL shows up in red under
SHLWAPI.DLL because it is missing a function named WNetRestoreConnectionA?
I also get a "Warning: At least one module has an unresolved import due to
a missing export function in a delay-load dependent module" message.
Function name : WNetRestoreConnectionA
But there is no guideline about how to solve it. Though, they say, it is not a problem.
i googled a little and found a suggestion.It says,
Turn off your compilers setting to assume you are programming for Win9x.
(I just lost which setting but it is not that difficult, use a #define...)
But i have no idea, how to do that in Visual Studio 2008 express.
Any suggestion how to solve it...
This usually indicates a problem with a dll; either you don't have permission, or a version is mismatched. Try running as Administrator to see if it is a permissions problem. If that doesn't help, try using the Dependency Walker.

Resources