I am trying to run a simple image show program in Eclipse CDT in MinGW built using cmake.
OpenCV Include Path : "E:\cv\opencv\eclipse\install\include"
OpenCV Library Path : "E:\cv\opencv\eclipse\lib" (has all libraries eg.libopencv_highgui310)
My Code is,
#include <iostream>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main(int argc, const char** argv) {
Mat img(500, 500, CV_8UC3, Scalar(100, 0, 0));
cout << "LOL!!!" << endl;
if (img.empty()) {
cout << "Error: Image cannot be loaded." << endl;
system("pause");
return -1;
}
namedWindow("Image Window", CV_WINDOW_AUTOSIZE);
imshow("Image Window", img);
if (waitKey(10) == 27) {
return -1;
}
destroyWindow("Image Window");
return 1;
}
When I build the code my console shows,
07:19:50 **** Incremental Build of configuration Release for project opencv_cpp ****
Info: Internal Builder is used for build
g++ "-IE:\\cv\\opencv\\eclipseBuild\\install\\include" -O3 -Wall -c -fmessage-length=0 -o "src\\faceDetect.o" "..\\src\\faceDetect.cpp"
g++ "-LE:\\cv\\opencv\\eclipseBuild\\lib" -o opencv_cpp.exe "src\\faceDetect.o" -llibopencv_highgui310 -llibopencv_core310 -llibopencv_imgproc310 -llibopencv_imgcodecs310 -llibopencv_objdetect310
07:19:56 Build Finished (took 5s.647ms)
When I run the program it just terminates and nothing happens. Even the print statement is not executed.
Here is the youtube link for the video of the problem,
https://youtu.be/kCrz_WPi_AI
Can someone help me with this?
Even I too faced this problem for longtime.
I researched through all the forum's , websites and all over google but i'm not able to find the answer.
But suddenly I thought of switching off the Windows Firewall and Windows Defender, And it magically works for me.. You too try it and let me know the result !
Happy coding :)
Related
Im trying to check if sdl is properly installed on my Ubuntu 20.04 and its not.
Running all on 64bit type.
This is my code:
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_timer.h>
bool initSDL()
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
std::cout << "Failed to init sdl: " << SDL_GetError() << std::endl;
return false;
}
if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG)
{
std::cout << "Failed to init sdl_image: " << IMG_GetError() << std::endl;
return false;
}
return true;
}
int main(int argc, char *argv[])
{
std::cout << "Code Starting..." << std::endl;
initSDL();
int winX = 900, winY = 600;
std::cout << "Code Exited Properly." << std::endl;
return 0;
}
And this is my output:
Code Starting...
Failed to init sdl: No available video device
Code Exited Properly.
Im running my code with this commands:
gcc -c src/*.cpp -I include -m64 -lstdc++ -std=c++11
gcc *.o -o out/main -lSDL2main -lSDL2 -lSDL2_image -m64 -lstdc++ -std=c++11
./out/main
My code strucure is this way:
Main directory 'sdl_hello_world'
->src -> contains 'main.cpp'
->out -> contains compiled 'main'
Some methods i tried was:
export DISPLAY=:0
export SDL_VIDEODRIVER=x11
So how do i fix this ?
EDIT: I also followed this tutorial (https://www.youtube.com/watch?v=P3_xhDIP7bc&list=PLvv0ScY6vfd-p1gSnbQhY7vMe2rng0IL0&ab_channel=MikeShah), and still it gave the same error. So i guess the problem is in some computer setting.
EDIT: SOLVED:
i followed almost all tutorials and fix methods on the internet to solve my issue which uses gcc in linux. Some solutions on stack overflow seemed to prefer to compile the source code on their own computer WHICH WORKED.
So im pretty sure the way ubuntu installs it on my computer/ idk im new to using sdl. Updating this as might come handy to anyone else.
Still curious, is there a chance i did something wrong, or could this be considered a bug ?
EDIT: followed this btw https://wiki.libsdl.org/Installation
I am trying to embed the gnuplot window into my application using the socket/plug concept in gtkmm 3 library. I have followed the example in the official page here and everything works as expected.
Then I moved to embedding gnuplot window. I modified the socket.cpp as follows:
#include <iostream>
#include <fstream>
#include <gtkmm.h>
#include <gtkmm/socket.h>
using namespace std;
class MySocketWindow : public Gtk::Window
{
public:
MySocketWindow()
{
auto socket = Gtk::manage(new Gtk::Socket());
add(*socket);
cout << "Socket id is: " << hex << socket->get_id() << endl;
show_all();
}
};
int main(int argc, char** argv)
{
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example.socket");
MySocketWindow win;
app->run(win);
return 0;
}
I compile/build the code with:
g++ --std=c++11 socket.cpp -o socket `pkg-config gtkmm-3.0 --cflags --libs`
And run it. A black socket window appears with Socket id is 3e0000b message printed on the terminal.
.\socket
Then I run gnuplot in x11 terminal with the corresponding window id above:
Now when I plot sin(x) in gnuplot, I am expecting the socket window to show the plot, but nothing happens. What I am doing wrong here?
I am running Ubuntu 16.04, 64-bit.
I found the cause of the problem on gnuplot's site - see my original question. Now it's left to find how to fix it on the socket's site.
I have been using openCv for a while, but have just moved to windows 10.
Now, existing applications will compile, but I cannot make a new one.
In a new project (visual studio 2015, release 64)
I am adding all the libs:
opencv_calib3d310.lib
opencv_core310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_photo310.lib
opencv_shape310.lib
opencv_stitching310.lib
opencv_superres310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
setting:
D:\opencv-master\build64\lib\Release;%(AdditionalLibraryDirectories)
and
D:\opencv-master\modules\highgui\include
D:\opencv-master\modules\imgcodecs\include
D:\opencv-master\modules\core\include
D:\opencv-master\modules\videoio\include
D:\opencv-master\modules\imgproc\include
%(AdditionalIncludeDirectories)
and adding the most basic:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include "stdafx.h"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (image.empty()) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
In visual studio, Intellisense is fine, no red underlines, everything looks good. When I try to compile tho...
'cv': a namespace with this name does not exist
'Mat': undeclared identifier
'image': undeclared identifier
...and many more. It is like it cannot find the libs, but i am linking them correctly, I am sure of it.
Can anyone assist me here?
I'm following the tutorial here for setting up OpenCV with Visual Studio (I have 2013 Community edition and OpenCV 2.4.10).
I have the following folder structure:
OpenCVTest
-OpenCVTest.sln
+x64
+Debug
- opencv_core2410d.dll
- opencv_highgui2410d.dll
- OpenCVTest.exe
- OpenCVTest.ilk
- OpenCVTest.pdb
- feck.png
And my source:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (!image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
When I run this in VS or on the command line, I get the following error:
C:\Users\mr\Documents\Visual Studio 2013\Projects\OpenCVTest\x64\Debug>OpenCVTest.exe feck.png
Could not open or find the image
Anybody know why this might be happening?
Update
I have tried giving the full path:
image = imread("C:\Users\mr\Documents\Visual Studio 2013\Projects\OpenCVTest\feck.png", IMREAD_COLOR); // Read the file
and placing the image at the same level as the .sln file, still no luck.
Place your image in OpenCVTest folder like this:
C:\Users\mr\Documents\Visual Studio 2013\Projects\OpenCVTest\OpenCVTest\feck.png
-OpenCVTest.sln
-OpenCVTest <- **HERE**
-ipch
+x64
+Debug
- opencv_core2410d.dll
- opencv_highgui2410d.dll
- OpenCVTest.exe
- OpenCVTest.ilk
- OpenCVTest.pdb
- feck.png
In the tutorial here, under "The local method", it reads:
Then you need to specify the libraries in which the linker should look
into. To do this go to the Linker ‣ Input and under the “Additional
Dependencies” entry add the name of all modules which you want to use:
opencv_core231d.lib
opencv_imgproc231d.lib
opencv_highgui231d.lib
opencv_ml231d.lib
opencv_video231d.lib
opencv_features2d231d.lib
opencv_calib3d231d.lib
opencv_objdetect231d.lib
opencv_contrib231d.lib
opencv_legacy231d.lib
opencv_flann231d.lib
I changed these from opencv_core{version}d.lib to opencv_core{version}.lib (not the debug library) and it seems to work okay now. I can step through the code in Visual Studio and the code appears to work.
I'm trying to run OpenCV on OSX in Xcode. I have downloaded the code from github. And used cmake to compile it.
Next I created a new Xcode project with the following code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread("img.jpg"); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
Next I've set the header search path to: /usr/local/include
After that I've added the libraries from /usr/local/lib in the "Build Phases" as seen in the screenshot below.
(source: opencv.org)
However, when I try to run I get the following error:
ld: library not found for -lopencv_core.3.0.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did I mis something?
In search for header path,
double tap the property. if you see the empty string
don't enter there,
slowly tap twice as it pop up a new list of properties
add the new one under the values press enter
still if its not working ,
check your string
You should add /usr/local/lib to the library search paths as well.