Opencv Mingw Build - c++

After trying without succed to install opencv with Mingw and codeblocks, i finnaly give up and download the precompiled libs from :
https://github.com/drewcrawford/drew-face/tree/master/opencv/build
But when i try to run some opencv code, my application crashed when it start and i have this message :
"The application was unable to start correctly (0xc0000005). Click OK to close the application."
Her is my code test :
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
cv::Mat image;
image = cv::imread("4010194A00101a_090.bmp",0);
return 0;
}

Related

Install opencv for C++ on Mac m1 chip properly

I've tried to install openCV for C++ using this tutorial : https://www.youtube.com/watch?v=KaTA-yK7dWA
and then try to set it up on Xcode using this video:
https://www.youtube.com/watch?v=2FYm3GOonhk&t=1266s
But when I ran the code:
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
///////////////// Webcam //////////////////////
int main() {
VideoCapture cap(1);
Mat img;
while (true) {
cap.read(img);
imshow("Image", img);
waitKey(1);
}
return 0;
}
I got the error:
ld: library not found for -lopencv_photo.4.5.5
clang: error: linker command failed with exit code 1 (use -v to see invocation)
don't know what to do, I'll be glad for help and guidance, it was much easier in python
Thanks in advance !
As the linker says - it cannot find the library lopencv_photo.4.5.5 to link against your program.
In Xcode the easiest option is to append the flag -lopencv_photo to Other Linker Flags in your Project Preferences.
Also - you wont be able to access a webcam on MacOS. There is no direct USB (serial) access to the video feed and it would require entitlements that requires a MacOS App project, not a command line tool.

"opencv_world454.dll was not found"

hello I had imported OpenCV into my C++ project but for some reason my code gives me this error.
CODE:
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
int main()
{
std::string path = "Resources/test.png";
cv::Mat img = cv::imread(path);
imshow("Image", img);
cv::waitKey(0);
return 0;
}
error:
I think it might be because of my paths but I'm not sure I think I got them right.
enter image description here
Edit: I reinstalled the setup and installed openCV in a new path and now I do have .dll files but it keeps giving me an error here are new screenshots
enter image description here
Maybe it will help someone
Instructions:
Open Project->Property
Configuration Properties->Debugging->Environment
PATH=C:\opencv\build\x64\vc15\bin;
You need your path to the folder
The solution was to install a new setup and install OpenCV into another path thank you to everyone who helped.

Files/directories to include in Visual Studio C++ to use CUDA?

I want to use CUDA/GPU in OpenCV in Visual Studio. For example, cuda::GpuMat. I successfully build OpenCV with the extra modules with CUDA enabled
I tried the following code
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/photo/cuda.hpp>
#include <opencv2/photo.hpp>
using namespace std;
using namespace cv;
int main(){
string imageName("input.bmp");
//CPU version
Mat image = imread(imageName.c_str(), IMREAD_GRAYSCALE);
//CUDA version
cuda::GpuMat imageGPU;
cuda::GpuMat downloadGPU;
Mat buff;
imageGPU.upload(image);
downloadGPU.download(buff);
imwrite("gpu.bmp", buff);
return 0;
}
But I get an unhandled exception error.
I originally downloaded OpenCV in C:\Users\me\Downloads\opencv
I then downloaded and installed the latest OpenCV extra modules with CUDA on in
In Property Pages->C/C++->General->Additional Include Directories, I have:
C:\Users\me\Downloads\opencv\build\include\opencv
C:\Users\me\Downloads\opencv\build\include\opencv2
C:\Users\me\Downloads\opencv\build\include\
In Property Pages->Linker->General->Additional Library Directories, I have:
C:\Users\me\Downloads\opencv\build\x64\vc15\lib
and in Property Pages->Linker->Input->Additional Dependencies, I have:
opencv_world343d.lib
opencv_world343.lib
what else am I supposed to include so I can get GpuMat to work properly?
Most of the cases, yes, but you need to know which library you need to add, it may be cufft.lib, cublas.lib, cudnn.lib, etc. It depends of the function you use inside your code.
Opencv includes a cmake include file that would set all of this up for you if you use cmake to build you VS test project. This file will be in the root of the opencv install directory, i.e. after building opencv running cmake --install or the equivalent in VS. The file is OpenCVConfig.cmake, and it would be included in the CMakeLists.txt file for your project. Then you would call FindPackage(OpenCV), which would locate the OpenCV install, setup a few variables, which you would then use to link against your app.
I can post a sample CMakeList.txt file if you feel that would help.

Visual Studio double execution just adding OpenCV directory

i noted that when i'm working with OpenCv and i run the debug it runs two times! Even if the code is just an empty main(). I configured VS in this way:
C/C++>>General>>Additional Include Directories: $(OPENCV_DIR)\Include
Linker>>General>> Additional library Directories: $(OPENCV_DIR)\x86\vc12\lib
Linker>>input>> Additional dependancies
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib
then i've done the same in the release using the .lib files without 'd'. Just doing like that i've the double execution, also with the following minimal code (note that the code is all under comment):
//#include <opencv2/core/core.hpp>
//#include <opencv2/highgui/highgui.hpp>
//#include <iostream>
//#include "opencv2/imgproc/imgproc.hpp"
//using namespace cv;
//using namespace std;
int main(int argc, char* argv[])
{
///Mat M(10, 5, CV_16UC1, Scalar::all(0));;
/// cout << M;
}
Another clue: in a more complex code, i use waitKey(0) and when i run the debug it runs the first time... after few seconds it stops and runs the second time... I noted that in the first run i cannot stop using the toolbar of VS (the 'stop' squared red button or the 'pause' one) while in the second run i can stop it using the toolbar. I tried creating a simple "hello world" code WITHOUT the OpenCv configurations and it runs just one time. So that i think that there is something wrong in my configurations.

Error executing openCV aplication on WINDOWS 7

Im using eclipse with opencv and i have this simple project:
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread(argc == 2 ? argv[1] : "lena.jpg", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
It apears to be correct acording to eclipse and it compiles just fine. But if i try to run it on debug mode from eclipse nothing happend and if i try to execute the .exe i get this error:
EDIT: These images are in spanish, but the error is exactly the same that the one in this post: opencv 2.4 error in windows 7 64 bit
I am runing it on a virtual machine with windows 7 x86.
PS: Sry for my english!
There's a chance that when Eclipse runs your application it looks for lena.jpg in a directory where this file is not present.
Make sure you put the JPG in the same folder as your source files and also in the same folder as the .exe.
Your code seems legit, and this problem shouldn't be happening. The best way to figure out what's really going on is to use the debugger and find out which of the calls trigger the error.