Frequently Asked Questions / Troubleshootings / HOWTOs
|
General Questions
How to install OpenCV properly?
Read installation guide
How can I get acquainted with OpenCV fast?
- Try to run Hawk (under Windows), load opencv\samples\c scripts and run them.
- Then you can move to higher-weight applications like facedetection, lkdemo, camshift etc.
- Also, scan through reference manual - it contains some example code as well.
- Search OpenCV archives at http://groups.yahoo.com/group/OpenCV
for the topic you are interesting in.
- Create new project on base of sample script and an OpenCV demo application and modify it as needed.
There are application wizards for Microsoft Developer Studio that create OpenCV-aware projects;
look for them at http://groups.yahoo.com/group/OpenCV
(Files section - you have to be registered OpenCV@yahoogroups.com user) or at
OpenCV SourceForge page.
Also read below how to create such a project from scratch
Where do I submit Bug reports for the computer vision library?
Send email to OpenCV@yahoogroups.com
Subject: BUG <....your title...>
How do I send bug reports for the Intel® Image Processing Library?
Send email to developer_support@intel.com
How do I join the web group for the library?
Send email to OpenCV-subscribe@yahoogroups.com,
after you are a member and select your logon, you can read the web group at
http://groups.yahoo.com/group/OpenCV
How do I modify the web group so that I don't receive email everyday?
To get the messages real time, or once a day as a daily digest,
you can go to http://groups.yahoo.com/mygroups
and choose your setting from the pull down list to the right of OpenCV.;
Ok, I found the group completely useless for me. How can I unsubscribe?
Mail to OpenCV-unsubscribe@yahoogroups.com
with subject [OpenCV] and arbitrary message contents.
How do I get support for the Image Processing Library (IPL)?
For the Image Processing Library, all support questions should go through:
http://support.intel.com/support/performancetools/support.htm (for release libraries)
https://premier.intel.com/scripts-quad/welcomeplsb.asp (for beta libraries)
In beta 3 IPL and OpenCV conflict. How to resolve it?
To be completely independent from IPL, OpenCV duplicates declarations of IplImage
and few other structures and constants if it is not told explicitly that IPL is present.
Defining HAVE_IPL before including OpenCV headers or putting "#include <ipl.h>"
before OpenCV headers resolves the conflict.
Does OpenCV works on other processors?
Yes, OpenCV itself is open source and it is quite portable, especially across
32-bit platforms. On the other hand, OpenCV can run much faster on Intel processors
because of IPP.
Windows® OS related Qs:
When I try to build one of the
apps, I get an error, streams.h not found.
You need DirectShow SDK that is now a part of DirectX SDK.
- Download DirectX SDK from msdn.microsoft.com/directx/
(It's huge, but you can download it by parts).
If it doesn't work for you, consider HighGUI that can capture video via VFW or MIL
- Install it TOGETHER WITH SAMPLES.
- Open <DirectXSDKInstallFolder>\samples\Multimedia\DirectShow\BaseClasses\baseclasses.dsw.
If there is no such file, it is that you either didn't install samples or the path has changed,
in the latter case search for streams.h and open a workspace file
(workspace files for Developer Studio .NET have different extension) located in the same folder.
- Build the library in both Release in Debug configurations.
- Copy the built libraries (in DirectX 8.x they are called strmbase.lib and strmbasd.lib)
to <DirectXSDKInstallFolder>\lib.
- In Developer Studio add the following paths:
<DirectXSDKInstallFolder>\include
<DirectXSDKInstallFolder>\samples\Multimedia\DirectShow\BaseClasses
to the includes' search path (at Tools->Options->Directories->Include files in case of Developer Studio 6.0)
Add
<DirectXSDKInstallFolder>\lib
to the libraries' search path (at Tools->Options->Directories->Library files
in case of Developer Studio 6.0)
NOTE: PUT THE ADDED LINES ON THE VERY TOP OF THE LISTS, OTHERWISE YOU WILL STILL GET
COMPILER OR LINKER ERRORS. This is necessary, because Developer Studio 6.0 includes some
older DirectX headers and libs that conflict with new DirectX SDK versions.
- Enjoy!
After installing DirectX SDK I'm still getting linker error about undefined
or redefined "TransInPlace" filter class constructors etc.
Read the instructions from the previous answer, especially about the order of
search directories.
When I use try to use cvcam, it just crashes
Make sure, you registered ProxyTrans.ax and SyncFilter.ax
CamShiftDemo can not be run
Make sure, you registered CamShift.ax and you have DirectShow-compatible camera
How to register *.ax (DirectShow filter)?
Open the file (within explorer) using regsvr32.exe (under Win2000 it is done by
Open with->Choose Program...->Browse...->c:\windows\system32\regsvr32.exe (path may be different).
You may remember association to save clicks later.
Filter couldn't be registered (regsvr32 reports an error)
The most probable reason is that the filter requires some DLLs that are not in the path.
In case of OpenCV make sure <OpenInstallFolder>\bin is in the path
LKDemo / HMMDemo reports an error during startup and no the view is completely black
To run either of these apps you will need VFW-compatible camera.
At startup the programs iterate through registered video capture devices.
It might be that they could not find one. Try to select the camera manually
by pressing "tune capture parameters" (camera) toolbar button. Then, try to
setup video format (the button on the left from camera) to make the camera work.
cvd.lib or cvd.dll are not found
cvd.dll means Debug version of cv.dll and cvd.lib is the import library for cvd.dll.
Open <OpenCVInstallFolder>\_dsw\opencv.dsw, select "cv" as active project and
select "Win32 Debug" configuration. Build the library and you will get bin\cvd.dll and
lib\cvd.lib files. The same is true for all of OpenCV components - name of binary,
ending with d means Debug version.
When compiling HighGUI I get the error message "mil.h is not found"
mil.h is a part of Matrox Imaging Library (MIL) that is usually supplied with
Matrox (or compatible) framegrabbers, such as Meteor, Meteor II etc.
- If you have such
a framegrabber and MIL installed, add mil\include and mil\lib to the search paths
within Developer Studio (submenu Tools->Options->Directories).
- If you do not have MIL, just ignore the error. The file mil.h is only required
to build MIL-aware version of Highgui "Win32 MIL Debug" or "Win32 MIL Release".
Select "Win32 Debug" or "Win32 Release" configuration of highgui
(submenu Build->Set Active Configuration...) instead - these versions of highgui
can still be used to grab video via VFW interface, work with AVIs and still images.
How can I debug DirectShow filter?
- Open workspace with the filter (e.g. opencv.dsw),
- select the filter as active project and build it in debug configuration,
- switch to explorer for a minute to register debug version of the filter
(e.g. regsvr32 camshiftd.ax) (it needs to be done only when debug/release version are switched - not
every time when filter is recompiled, because registry stores only the filter name),
- get back to Developer Studio and start debugging session (F5).
It will ask, what application do you want to run to debug the module.
You may choose camshiftdemo to debug camshift.ax and
DirectX SDK tool graphedit to debug arbitrary DirectShow filter.
- Within graphedit build filter graph (e.g. camera->camshift->renderer)
- Save the graph (you may just load it next time)
- Set the breakpoint inside ::Transform method of the filter or in other location.
- Run the filter and ... have fun
(note: this is a lengthy answer)
To create your own OpenCV-based project in Developer Studio
from scratch do the following:
- Within Developer Studio create new application:
- select from menu "File"->"New..."->"Projects" tab.
Choose "Win32 Application" or "Win32 console application" - the latter is
the easier variant and the both sample projects have this type.
- type the project name and choose location
- you may create own workspace for the project ("Create new workspace")
or include the new project into the currently loaded workspace
("Add to current workspace").
- click "next" button
- choose "An empty project", click "Finish", "OK".
After the above steps done Developer Studio will create the project
folder (by default it has the same name as the project),
<project name>.dsp file and, optionally, <project name>.dsw,.ncb ... files
if you create own workspace.
- Add a file to the project:
- Customize project settings:
- Activate project setting dialog by choosing menu item
"Project"->"Settings...".
- Select your project in the right pane.
- Tune settings, common to both Release and Debug configurations:
- Select "Settings For:"->"All Configurations"
- Choose "C/C++" tab -> "Preprocessor" category -> "Additional Include Directories:".
Add comma-separated relative (to the .dsp file) or absolute paths
to opencv\cv\include, opencv\otherlibs\highgui and, optionally,
opencv\cvaux\include.
- Choose "Link" tab -> "Input" category -> "Additional library path:".
Add the paths to all neccessary import libraries
- Tune settings for "Debug" configuration
- Select "Settings For:"->"Win32 Debug".
- Choose "Link" tab -> "General" category -> "Object/library modules".
Add space-separated cvd.lib, highguid.lib, cvauxd.lib (optionally)
- You may also want to change location and name of output file. For example,
if you want the output .exe file to be put into the project folder, rather
than Debug/ subfolder, you may type ./<exe-name>d.exe in
"Link" tab -> "General" category -> "Output file name:".
- Tune settings for "Release" configuration
- Select "Settings For:"->"Win32 Release".
- Choose "Link" tab -> "General" category -> "Object/library modules".
Add space-separated cv.lib, highgui.lib, cvaux.lib (optionally)
- Optionally, you may change name of the .exe file:
type ./<exe-name>.exe in "Link" tab -> "General" category -> "Output file name:".
- Add dependency projects into workspace:
- Choose from menu: "Project" -> "Insert project into workspace".
- Select opencv\cv\make\cv.dsp.
- Do the same for opencv\cvaux\make\cvaux.dsp, opencv\otherlibs\highgui\highgui.dsp.
- Set dependencies:
- Choose from menu: "Project" -> "Dependencies..."
- For "cvaux" choose "cv",
- for "highgui" choose "cv",
- for your project choose all: "cv", "cvaux", "highgui".
The dependencies customization allows to automatically build debug versions
of opencv libraries and rebuild the binaries if the sources are changed somehow.
- That's it. Now compile and run everything.
Linux Related Qs:
TODO
Technical Questions on Library use:
How to access image pixels
(The coordinates are 0-based and counted from image origin, either top-left
(img->origin=IPL_ORIGIN_TL) or bottom-left (img->origin=IPL_ORIGIN_BL)
- Suppose, we have 8-bit 1-channel image I (IplImage* img):
I(x,y) ~ ((uchar*)(img->imageData + img->widthStep*y))[x]
- Suppose, we have 8-bit 3-channel image I (IplImage* img):
I(x,y)blue ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
I(x,y)green ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
I(x,y)red ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]
e.g. increasing brightness of point (100,100) by 30 can be done this way:
CvPoint pt = {100,100};
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3] += 30;
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+1] += 30;
((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3+2] += 30;
or more efficiently
CvPoint pt = {100,100};
uchar* temp_ptr = &((uchar*)(img->imageData + img->widthStep*pt.y))[x*3];
temp_ptr[0] += 30;
temp_ptr[1] += 30;
temp_ptr[2] += 30;
- Suppose, we have 32-bit floating point, 1-channel image I (IplImage* img):
I(x,y) ~ ((float*)(img->imageData + img->widthStep*y))[x]
- Now, the general case: suppose, we have N-channel image of type T:
I(x,y)c ~ ((T*)(img->imageData + img->widthStep*y))[x*N + c]
or you may use macro CV_IMAGE_ELEM( image_header, elemtype, y, x_Nc )
I(x,y)c ~ CV_IMAGE_ELEM( img, T, y, x*N + c )
There are functions that work with arbitrary (up to 4-channel) images and matrices
(cvGet2D, cvSet2D), but they are pretty slow.
How to access matrix elements?
The technique is very similar.
(In the samples below i - 0-based row index, j - 0-based column index)
- Suppose, we have 32-bit floating point real matrix M (CvMat* mat):
M(i,j) ~ ((float*)(mat->data.ptr + mat->step*i))[j]
- Suppose, we have 64-bit floating point complex matrix M (CvMat* mat):
Re M(i,j) ~ ((double*)(mat->data.ptr + mat->step*i))[j*2]
Im M(i,j) ~ ((double*)(mat->data.ptr + mat->step*i))[j*2+1]
- For single-channel matrices there is a macro CV_MAT_ELEM( matrix, elemtype, row, col ),
i.e. for 32-bit floating point real matrix
M(i,j) ~ CV_MAT_ELEM( mat, float, i, j ),
e.g.
filling 3x3 identity matrix:
CV_MAT_ELEM( mat, float, 0, 0 ) = 1.f;
CV_MAT_ELEM( mat, float, 0, 1 ) = 0.f;
CV_MAT_ELEM( mat, float, 0, 2 ) = 0.f;
CV_MAT_ELEM( mat, float, 1, 0 ) = 0.f;
CV_MAT_ELEM( mat, float, 1, 1 ) = 1.f;
CV_MAT_ELEM( mat, float, 1, 2 ) = 0.f;
CV_MAT_ELEM( mat, float, 2, 0 ) = 0.f;
CV_MAT_ELEM( mat, float, 2, 1 ) = 0.f;
CV_MAT_ELEM( mat, float, 2, 2 ) = 1.f;
How to process my data with OpenCV
Suppose, you have 300x200 32-bit floating point array, that
resides in 60000-element array.
int cols = 300, rows = 200;
float* myarr = new float[rows*cols];
// step 1) initializing CvMat header
CvMat mat = cvMat( rows, cols,
CV_32FC1, // 32-bit floating-point, single channel type
myarr // user data pointer (no data is copied)
);
// step 2) using cv functions, e.g. calculating l2 (Frobenius) norm
double norm = cvNorm( &mat, 0, CV_L2 );
...
delete myarr;
Other scenaria are described in the reference manual.
See cvCreateMatHeader, cvInitMatHeader, cvCreateImageHeader, cvSetData etc.
How to load and display image
/* usage: prog <image_name> */
#include "cv.h"
#include "highgui.h"
int main( int argc, char** argv )
{
IplImage* img;
if( argc == 2 && (img = cvLoadImage( argv[1], 1)) != 0 )
{
cvNamedWindow( "Image view", 1 );
cvShowImage( "Image view", img );
cvWaitKey(0); // very important
cvDestroyWindow( "Image view" );
cvReleaseImage( &img );
return 0;
}
return -1;
}
How to find and process contours
Look at squares demo
How to calibrate camera using OpenCV
TODO