I'm trying to install opencv on windows, here are my steps:
downloaded opencv 2.4.3 from website
run the exe, extracted the folder in the same path
opened eclipse (with MinGW previously set and configured)
created new project XYZ
added new folder "src"
added new class "main.cpp"
added the following code:
hash include <cv.h>
hash include <highgui.h>
using namespace cv;
int main(int argc, char** argv) {
Mat image;
image = imread(argv[1], 1);
if (argc != 2 || !image.data) {
printf("No image data \n");
return -1;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
imshow("Display Image", image);
waitKey(0);
return 0;
}
added the two paths
"E:\Sources\opencv\build\include"
"E:\Sources\opencv\build\include\opencv"
got the compilation error "Symbol 'cv' could not be resolved"
Please advice if any step is missing
you gonna need the latest stable version of openCV 2.4.3 .
Eclipse Juno ! (Eclipse IDE for C/C++ Developers )
And
MinGW - Minimalist GNU for Windows
we will ignore x86/64 choice, since we gonna work with a 32 compiler / and 32 openCV build, even though the system is a 64 one !
Step 1 : Download and Install
Eclipse
Download Eclipse from and decompress the archive . ( I assumed that you already have JRE on your computer , if not ! download and install it ) .
MinGW
Download MinGW . the installer will lead you through the process !
you might have to add the bin directory to the path ! (Default path : C/MinGW/bin )
OpenCV
Download openCV exe from the link , extract the files (in the C:/ directory in this tutorial ) .
Make sure you have the file structure below .
don't forget to add the bin directory => Path !
As I mentioned earlier ! I'll use x86 build even if i have a 64 OS to avoid compiler problems and to keep this tutorial open to x86 OS users !
Step 2 : Create and Configure
Open the Eclipse IDE !
Create a new C++ project : File > New > C++ Project
Choose a Hello Word Project to have a pre structured one !
Don't forget to select the MinGW toolchains
Click Finish and let's get to work !
Now that you have you first Hello word project ! replace the Code in the Soure file .cpp by the code below
///////////////CODE///////////
#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] : "lenna.png", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
///////////////CODE///////////
Obviously there are multiple errors on the code , yes ! we have to link the libraries !
Now go to Properties >> C/C++ Build >> Settings
on the Tool Setting tab >> GCC C++ Compiler >> Includes and include opencv path !
[opencvDir\build\include]
Now scroll to MinGW C++ Linker >> Libraries and add the Library search path [opencvDIR\build\x86\mingw\lib]
in the Libraries part ! we add as much librarie as we need for the project !
here I added 4 libraries just for tutorial sake even if well need only the highgui one for our test code to work !
The libraries names can be found on the [opencvDIR\build\x86\mingw\lib]
Example ! for libopencv_video243.dll.a wee add opencv_video243 in the linker !
click OK !
Now we can build our first project !
You figured that you have to add a picture to the project as implied in the source code "lenna.png"
Use lenna for good luck
Build and Run the project !
If you see the beautiful lady :) Congrats :)
have a look here for snapshots!
opencveclipse-on-windows
cv.h is for the old C API. To use the Cpp API try the following:
#include <opencv2/opencv.hpp>
Related
I installed OpenCV3 with brew follow other's guide on the Internet,
1,install brew
usrs/local/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2,then I install OpenCV3
brew install opencv3
3,after install, my path of OpenCV3 is
/usr/local/Cellar/opencv3/3.2.0
#in fact this path "/usr/local/Cellar/opencv3/3.2.0" contains all
software installed by brew, and I have also try
to install opencv,
its path is "/usr/local/Cellar/opencv/2.4.13.2"
4, setup my ~/.bash_profile file
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
# Homebrew
#export PATH=/usr/local/bin:$PATH
# OpenCV3
export PATH="/usr/local/opt/opencv3/bin:$PATH"
5.1,add "lib" and "include" path to my Xcode(version 8.3.1, 8E1000a)
add openCV3 to "Header search paths" and "Library search Paths"
5.2,and add something in "Build Phases" Tab
add many opencv's dylib files(which themselves in "/usr/local/Cellar/opencv/2.4.13.2/lib") and three C++ dynamic linking files here
6, some thing wrong happened when I run my C++ code
Mat cv_input_image = imread("image_0001.jpg");
cout << "rows:" << cv_input_image.rows << endl;
cout << "cols:" << cv_input_image.cols << endl;
cout << "channels:" << cv_input_image.channels() << endl;
it run successfully but the result is worng:
rows:0
cols:0
channels:1
my effort:
I have try many times to install OpenCV with brew and different setup method in my Macbook(I am new in Mac), all of then didn't work well, and I can successfully include and others about OpenCV, I just don't know where I could start to solve this problems?
by the way, I have also try my openCV(not openCV3), I can include them in my C++ code successfully
and I have a complicated C++ code, the first step is to read a picture ,and there has an "error information":
inline
MatConstIterator::MatConstIterator(const Mat* _m)
: m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
{
if( m && m->isContinuous() )
{
sliceStart = m->ptr();
sliceEnd = sliceStart + m->total()*elemSize;
}
seek((const int*)0);// <=======something wrong here
}
my Xcode gives me information:
Thread 1: EXC_ARITHMETIC(code=EXC_I386_DIV, subcode=0x0)
in the left of my Xcode, there has a Threads list form index 0 to 9,
and when this happened, An arrow point to index 1:"cv::MatConstIterator::MatConstIterator(cv::Mat const*)"
wish for your help~~
When compiled with Xcode, the executable is put in some weird temp folder. Therefore imread("image_0001.jpg") will most likely fail since you use relative path here (i.e. image_0001.jpg needs to be at the same folder as the executable. To fix this, try to use the absolute path to the image, i.e. /Users/your_home/Desktop/image_0001.jpg.
The other error might due to the fact that cv_image_input is empty after the failed imread.
I'm working on Qt application, that has to compute some data using Scilab's numerical engine. My OS is Ubuntu 14.04 with installed Scilab v.5.5.0 and QtCreator v.3.2.1 (Qt 5.3.2).
I'm using a simple code example provided in scilab help:
/****** INITIALIZATION **********/
#ifdef _MSC_VER
if ( StartScilab(NULL,NULL,NULL) == FALSE )
#else
if ( StartScilab(getenv("SCI"),NULL,NULL) == FALSE )
#endif
{
fprintf(stderr,"Error while calling StartScilab\n");
}
/****** ACTUAL Scilab TASKS *******/
SendScilabJob("myMatrix=['sample','for the help']");
SendScilabJob("disp(myMatrix);"); // Will display !sample for the help !
SendScilabJob("disp([2,3]+[-44,39]);"); // Will display - 42. 42.
/****** TERMINATION **********/
if ( TerminateScilab(NULL) == FALSE ) {
fprintf(stderr,"Error while calling TerminateScilab\n");
}
My problem is that after clicking "Run", I get an alert as follows:
/home/med/Dokumenty/QTWorkspace/build-QTtest-Desktop_Qt_5_3_GCC_32bit-Debug/QTtest: error while loading shared libraries: libscicall_scilab.so.5: cannot open shared object file: No such file or directory
I tried to add following line to qmake .pro file, but without any results:
LIBS += /usr/lib/scilab/libscicall_scilab.so.5
The library already is in specified dir (I've checked this manually). Before that I was trying a lot of another settings - still without success.
Could anyone provide the proper solution of this problem?
try adding the location of your lib to your LD_LIBRARY_PATH
Try to use this in your project file:
LIBS = -L/usr/lib/scilab -lscicall_scilab
You will need to rerun qmake then to regenerate the Makefile(s). Make sure that you have 32 bit library of scilab or change the build to 64 bit should that be the issue.
Here is my code:
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace cv;
using namespace std;
int main()
{
Mat src;
//src.create(200,500,CV_8UC3);
src = imread( "a.bmp", 1 );
namedWindow( "Display window", WINDOW_AUTOSIZE );
if(!src.data)
cout<<"Could not open or find the image" << std::endl ;
else
imshow( "Display window", src);
waitKey(0);
return 0;
}
It is always executing the if part
when I am using src.create instead of imread() it shows an empty image.
To debug your issue you should try to confirm that the image path is correct.
As suggested in the comments, try specifying the full absolute path of the file. Remember to to use escape slashes if you are on windows (e.g. c:\a.bmp will need to be "c:\a.bmp")
OR
If you are executing your application from Visual Studio then you can configure the working directory to be that of the bitmap too! (OpenCV cvLoadImage() does not load images in visual studio debugger?)
You can also try using cvLoadImage instead of imread. If cvLoadImage can open the file then it is possible that you have a mix of release and debug libraries causing you an issue as per:
OpenCV imread(filename) fails in debug mode when using release libraries
The OpenCV documentation has mentioned imread() would return an empty matrix ( Mat::data==NULL ) if the image file cannot be read.
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#imread
You should check if the "a.bmp" file is in your current working directory. The IDE (visual studio) may set executable's working directory (Debug/... Release/... ) on purpose. Using an absolute path to "a.bmp", or starting executable in an expected directory from command line would also help, provided that "a.bmp" is a valid BMP file and you have the right file system permission to read it.
I was having the same issue on visual studion and imread returning null data.
img = cv::imread("c:\\data\\a.bmp",1);
Note the \\ delimiters to enable windows to correctly parse the path.
Your opencv libs should match the configi.e., Debug or Release of your application in Visual Studio or whatever build you are using (If you are using pre-built binaries) for WINDOWS.
I'm trying to use LibVLC in a Qt 5 program to open a VLC instance and play a video.
The following code comes from https://wiki.videolan.org/LibVLC_Tutorial/
I'm using Linux.
.pro :
TEMPLATE = app
TARGET = projectLoic
INCLUDEPATH += . vlc
QT += widgets
# Input
HEADERS +=
SOURCES += main.cpp
LIBS +=-lvlc
main :
#include <vlc/vlc.h>
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
// Load the VLC engine
inst = libvlc_new(0, NULL);
// Create a new item
m = libvlc_media_new_path (inst, "/home/........mp3");
// Create a media player playing environement
mp = libvlc_media_player_new_from_media (m);
// play the media_player
libvlc_media_player_play (mp);
return app.exec();
}
The compilation is fine. But the program immediatly crashes when I build it (with Qt Creator). Any idea?
Many thanks
Many things could cause this crash. The best is to get VLC source code to trace back the issue. Passing the option '--verbose=2' when initializing libVLC can help as well.
In my case the cause of the crash was due to this bug in the ubuntu package of vlc:
https://bugs.launchpad.net/ubuntu/+source/vlc/+bug/1328466
When calling libvlc_new() vlc modules and their dependent libraries are loaded into memory. The qt module of LibVLC was searching for Qt4 shared objects instead of Qt5 (manually installed).
The solution was to rebuild the module cache which was outdated an pointing to Qt4 binaries. You can reset it on the command line:
sudo /usr/lib/vlc/vlc-cache-gen -f /usr/lib/vlc/plugins/
Or pass to vlc the option:
--reset-plugins-cache
I have never used this library, but Are you using exactly this code?
m = libvlc_media_new_path (inst, "/home/........mp3");
This path may be the problem.
What distribution of Linux are you using?
I ran into this same problem with Qt5 and LibVLC, and the primary cause (Ubuntu 12.04 LTS and 14.04 LTS), was that LibVLC was loading the qt4 interface plugin, which conflicted with Qt5. If you check your call stack, you'll most likely see that at a Qt4 library was being loaded, causing the crash.
If this is the problem, there are only 3 options (tested with LibVLC 2.2 and Qt5 on Ubuntu 12.04 and 14.04 LTS 64 bit).
The first (worst) is to delete the qt4 user interface plugin. You can test this is the problem by moving and running and then setting it back. Deleting will break your regular VLC player most likely.
Second option is to create a copy of the plugins directory and set that in your runtime path using VLC_PLUGIN_PATH, environment variable. but I've had trouble getting that to work without changing the original plugin path folder also (which will break your VLC player unless you modify your shortcuts, etc. to also set VLC_PLUGIN_PATH.
The third option, and what I ended up doing, was to custom build my own static LibVLC binary with a few edits to the source code so that it will not load the qt4 interface plugin installed with VLC. You can follow these steps to do this.
1) Download VLC Source Code for your platforms distribution.
http://download.videolan.org/pub/videolan/vlc/
Make sure you download the version matching your distribution. For
example, match the VLC version to what is installed with Ubuntu.
2) Extract source code to folder
3) Install dependencies for the OS distribution
sudo apt-get build-dep vlc
4) Modify src/modules/bank.c
Edit the module_InitDynamic function
Add the following code at the top of the function:
// HACK TO DISABLE QT4 PLUGIN
if(strstr(path, "qt4") != NULL)
return NULL;
// END HACK
3) From terminal
./bootstrap
./configure --disable-qt --disable-skins2 --enable-xcb --prefix=/home/$USER/vlc-custom_build_output_folder_name
./make
./make install
4) Copy/Save the resulting files in the install folder.
Then just link against this library instead.
I am trying to work out a simple hello world for OpenCV but am running out of ideas as to why it is not working.
When I compile and run this code:
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
IplImage* img = cvLoadImage( "myjpeg.jpg" );
cvNamedWindow( "MyJPG", CV_WINDOW_AUTOSIZE );
cvShowImage("MyJPG", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "MyJPG" );
return 0;
}
I get a grey box about 200x200 instead of the indicated .jpg file. If I use a different jpg I get the same kind of window, and if I put an invalid filename in, I get a very tiny window (expected).
I am using Visual Studio 2008 under Windows 7 Professional.
Most of the sample programs seem to work fine, so I am doubly confused how that code loads the sample jpgs just fine but in the code above it does not work (even tried the sample jpeg).
Update
The executables produced by compiling work fine, however the Visual Studio 2008 debugger loads a null pointer into img every time I try to run the debugger - regardless if the file location is implicit or explicit.
It really seems like there's a problem with the path to myjpeg.jpg since the current directory could be different when you're running under the debugger.
By default, the current directory that the Visual Studio debugger uses is the directory containing the .vcproj file, but you can change it in the project properties (Debugging -> Working Directory).
Are you 100% sure that you pass the absolute path correctly? Try to pass the same path to fopen and see if it also returns NULL. If so, then the path is incorrect.
If you want to see exactly what file is the library trying to open you can use Project Monitor with a filter on myjpeg.jpg.
Which version of OpenCV are you using? I've tried your code on the latest (OpenCV2.0) and it works fine. You can download OpenCV2.0 from here.
If you want the latest build, you can get check it out with SVN from here.
Try to add HAVE_JPEG into preprocessor definitions.
I encountered the same problem. The Debug version does not load the image, but when I compile and link it as a Release it works. I hope this helps