Getting Webcam to work in OpenCV - c++

I'm trying to get my webcam to capture video in OpenCV, version 2.2 in Windows 7 64 bit. However, I'm having some difficulties. None of the sample binaries that come with OpenCV can detect my webcam. Recently I came across this posting which suggested that the answer lies in recompiling a file, opencv_highgui with the property HAVE_VIDEOINPUT HAVE_DSHOW in the property page.
Can't access webcam with OpenCV
However, I'm unsure about procedurally how to do this. Can someone recommend as to how to go about this? Thanks.

Roughly, these are the important steps:
Download the OpenCV 2.2 source code,
set up a project to compile it, according to the InstallGuide,
make any changes you need to make in the code,
build the opencv_highgui library (dll and lib files, probably), and
replace these in your original project.
If you can configure the project to generate the highgui files only (and not every library in OpenCV), do so, since the change you need to do shouldn't affect other modules. This saves some time.
The detailed instructions to build OpenCV are in: http://opencv.willowgarage.com/wiki/InstallGuide. You should follow this guide.

Related

CGAL draw function is giving 'CGAL_USE_BASIC_VIEWER is not defined' error in Visual Studio

I am trying to generate mesh and 3D object from point cloud. I have searched lots of libraries and I decided to use CGAL. I followed this youtube tutorial. Due to the fact that I want to see the objects, I need to use Qt5 library (as mentioned here) and I downloaded it. And it worked as in tutorial.
Libraries and applications I've used
CMake 3.15.3
CGAL-4.13.1
Qt 5.13.0
Boost 1_71_0
The problem is that when I call the CGAL::draw() function it gives me this error
Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined.
When I have searched for it, I have generally found
QMAKE_CXXFLAGS +=-DCGAL_USE_BASIC_VIEWER
LIBS+=-DCGAL_USE_BASIC_VIEWER
.pro file solution (I don't have .pro file) and this
I couldn't handle with them.
Is there a windows visual studio solution?
How do we define CGAL_USE_BASIC_VIEWER?
Do I need to import some Qt5 libs?
Thanks in advance!
UPDATE
My problem was that I was following the video. And in the video, the guy didn't build the source with cmake, he added libraries etc with manually.
When I build the source code with cmake, it works.
There is a very simple tutorial Here.
With cmake, you need to do the following to use CGAL basic viewers:
1) use cgal with QT5
find_package(CGAL COMPONENTS Qt5)
2) define CGAL_USE_BASIC_VIEWER
add_definitions(-DCGAL_USE_BASIC_VIEWER)
3) link your program with CGAL_Qt5
target_link_libraries(myexe PUBLIC CGAL::CGAL_Qt5)
Have a look to the different examples in CGAL that uses basic viewer, for example draw_triangulation_3.cpp and its CMakeLists.txt.

Can't configure OpenCV with Qt properly?

I'm trying to configure OpenCV (3.1) with Qt Creator on Windows 32 and 64 bit for a long time to create a GUI application but I just can't seem to solve this configuration part. I've tried and read a lot of tutorials there are on the internet (https://zahidhasan.wordpress.com/2014/08/19/qt-5-3-1-64-bit-mingw-windows/ for example) but with no success.
When I try to run my program, I'm getting these errors:
enter image description here
To use a library, you have to reference its headers (and that is what you have done correctly with your #include directives).
But you also have to point the linker to the location and names of libraries to link. That is currently missing in your configuration, because you get undefined reference errors from linker.
Hard to tell anything more without knowing more details on your setup so far.
Depending on your environment and the build of OpenCV you need, you need to configure your project to use static libraries or DLLs (I assume we speak about Windows here).
As you use imread(), you will surely need the opencv_highgui*.* library, but this will surely not suffice.
See e.g. this OpenCV documentation for a complete list of OpenCV libraries.

Including OpenCV source in project without installation

I'm currently trying to setup an OpenCV project using CMake.
I want to have the highest portability between machines so I thought I can achieve it by including the OpenCV source and compiling it and link it in CMake to the executable.
I'm not quite sure how to go about it because I'm a beginner to CMake and OpenCV. However, I would like to avoid installing it on the machine as much as possible as I would just want to build it and run on a machine.
So far, I've looked at the possibility of including the source of OpenCV in the CMakeFiles.txt like so:
add_subdirectory(opencv-3.1.0)
target_link_libraries(foo opencv-core)
However, it hasn't worked for me so far.
Can anyone provide me with suggestions?
Thank you.
EDIT:
The main problem I've been encountering so far is that once I use make install to move all the binaries into place, it will try to move the compiled version of OpenCV into the install location which I'm not sure how to avoid using it.

Adding third party libraries to an OpenCV project on Xcode

I am new to the XCode environment so apologies if this sounds trivial.
I am trying to use a third party library using for OpenCV that helps me do some blob analysis, CCL etc. Hosted here
I have searched a lot but there doesn't seem to be much documentation on how to go about adding and using these new libraries. I am using XCode 4.5.2, OpenCV 2.4.2.
When I simply add all the header files to the project folder and #include them in the source code, it fails to compile. I have also tried adding the "Header Paths" but it doesn't help. What am I missing?
I have tried to follow the instructions (compiling it using the terminal but it doesn't compile too) I am not clear on how or when exactly to use CMAKE.
Any help will be appreciated. Thank you.
I would suggest you using CvBlob on google code which is different from the one on willowgarage, I have got recently confused with this so take a look at this question for alternative blob analysis libraries.
Moreover, CvBlob has also a good support community here. (Search on "[cvblobslib]" or on "[blob] [opencv]")
Try this: cvBlob: OSX installation
Once you get it compiled, you need to include the library under Link Binary with Libraries in Build Phases. (This screenshot shows the core, imgproc, and highgui libraries. Your cvBlob library would go in the same place.)

OpenCV facedetect example won't load cascade classifier xml

I'm working on a application that requires OpenCV object detection using Haar cascade classifier.
I'm using OpenCV 2.3.1 with VS2010 on a 64bit Windows Machine.
I compiled and built OpenCV myself and didn't use any pre-compiled binaries.
First, I wanted to start meddling with the example facedetect.cpp that's included in OpenCV.
I built it with no errors, but when I'm trying to run it won't open the cascade classifier xml file (the CascadeClassifier.load() function returns false). I didn't change anything from the sample source code.
I'm using the xml file that is distributed with OpenCV so the problem isn't with the xml file.
I also made sure that the application can access and read the file using a simple fopen.
I believe (but not sure) that the problem seems to be that the cascade classifier is of an "old" type.
But in the OpenCV documentation it is specifically implied that the new CascadeClassifier object can open both "old" and "new" cascade classifiers.
Here's a link: http://opencv.itseez.com/modules/objdetect/doc/cascade_classification.html#cascadeclassifier-load
I even tried using the pre-compiled OpenCV2.2 binary and it works excellent with that xml. And then I tried to compile the 2.2 sample source code, and again it couldn't load the xml.
I'm aware that I can try using the old object CvHaarClassifierCascade, but I prefer to use the latest version of OpenCV and its objects.
Does anyone have a clue what am I doing wrong?
Give the complete path of the xml file
String face = "c:/data/xml/haarcascade_frontalface_alt.xml";
It should work!
I had the same situation. I solved it when I realized that I’m linking release libs in Debug configuration. Changing opencv_231*.lib to opencv_*231d.lib has solved the problem.
CascadeClassifier::load is not the only function causing such troubles, see this thread for details: OpenCV imread(filename) fails in debug mode when using release libraries.
I got this working by using notepad++. I converted all the relevant xml files to ANSI and also deleted the first line <?xml version="1.0"?> and then rewrote it by hand.
If you are using windows then check the path. Concern is
escape sequence in the path.
forward or backward slash depending on operating system.
It should be like C:\\Ceemple\\data\\haarcascades\\haarcascade_frontalface_alt.xml.
(by the way I am using Ceemple IDE)