View Full Version : Installing OpenCV
I have been having quite some trouble in getting OpenCV installed. After doing a quick search, "installing opencv," I got no good results. I have tried many of the installation techniques listed in various websites, found by searching, installing opencv (http://bit.ly/1gqCJP5). <<Hopefully, no one finds that offensive :(. Does anyone have a link to some good documentation on how to quickly install OpenCV? I am interested in compiling it, because I can use Git and get the latest code!
Question that will definitely help troubleshoot: What OS are you running?
Currently Debian, however, I will switch to Ubuntu whenever possible. Ubuntu is basically Debian, with tons of add-ons!
billbo911
29-11-2013, 23:58
I have been having quite some trouble in getting OpenCV installed. After doing a quick search, "installing opencv," I got no good results. I have tried many of the installation techniques listed in various websites, found by searching, installing opencv (http://bit.ly/1gqCJP5). <<Hopefully, no one finds that offensive :(. Does anyone have a link to some good documentation on how to quickly install OpenCV? I am interested in compiling it, because I can use Git and get the latest code!
If you used the install directions in the link you provided, you undoubtedly made it to this page (http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html).
Was there an issue with following those steps? I know it is written for Linux, but I followed it for Ubuntu and was successful. I believe it "should" work as well for Debien, as long as you compensate for any minor differences.
Yes. That is the first link that I clicked on. However, it does not include a comprehensive list of resources required by OpenCV. I want to have maximum compatibility, so I will make sure to get everything, even if I have to compile it myself! Also, that says,
cmake [<some optional parameters>] <path to the OpenCV source directory>
I do not know the optional parameters. I haven't messed around with CMAKE that much, so I do not know how to get the list of parameters.
Right now, I am following a tutorial on ozbots:
http://www.ozbotz.org/opencv-installation-2-3-1/http://www.ozbotz.org/opencv-installation-2-3-1/
Since that is for OpenCV 2.3.1, could that cause any faults?
Thanks!
otherguy
30-11-2013, 11:30
This page (http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/), with instructions for opencv installation on debian, explains the cmake "optional parameters" a bit more.
hzheng_449
30-11-2013, 12:03
Also in Ubuntu 12.04 (which by the way is the LTS, so if you're gonna switch switch to 12.04) you can just apt-get the libraries (and of course it will also list out and allow you to install all the dependencies). This is what ended up doing since it's the easiest option...
link to apt-get installing opencv (http://askubuntu.com/questions/334158/installing-opencv) (the package may be slightly out of date)
On a slight tangent, I'm not really a fan of cmake, and if you aren't either, it's worth the time to google how to compile openCV projects with g++.
That helps quite a bit. That article describes a little more on how to configure CMAKE. Right now, I am stuck on installing FFMPEG, because Apt won't download the current version of YASM (I have already run apt-get update). Currently, I am performing a distribution upgrade of Ubuntu, because I am running 12.04. Hopefully that will help! What webcam do you guys suggest for powerful vision tracking? I was thinking of a camera with a high shutter speed, low ISO, and high aperture. That would allow me to set up a spotlight of light, to be retroreflected to the camera. The camera would only be able to capture that bright light!
Also in Ubuntu 12.04 (which by the way is the LTS, so if you're gonna switch switch to 12.04) you can just apt-get the libraries (and of course it will also list out and allow you to install all the dependencies). This is what ended up doing since it's the easiest option...
link to apt-get installing opencv (http://askubuntu.com/questions/334158/installing-opencv) (the package may be slightly out of date)
On a slight tangent, I'm not really a fan of cmake, and if you aren't either, it's worth the time to google how to compile openCV projects with g++.
I agree. I am not a fan of CMAKE either. I was just going to use an IDE like Netbeans! That would get rid of all the confusion, caused by setting up! I will google about how to compile OpenCV projects using g++. I believe it uses PKG-CONFIG, so it shouldn't be rocket science!
While compiling OpenCV, at 20%, I got this error:
[ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
[ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/rgbe.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.3.0.0] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
Does anyone know what it could be?
brennonbrimhall
30-11-2013, 21:51
I agree. I am not a fan of CMAKE either. I was just going to use an IDE like Netbeans! That would get rid of all the confusion, caused by setting up! I will google about how to compile OpenCV projects using g++. I believe it uses PKG-CONFIG, so it shouldn't be rocket science!
While no build system is perfect, CMake does a good job of managing cross-platform building. I wouldn't dismiss it too readily. But we digress.
While compiling OpenCV, at 20%, I got this error:
[ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
[ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/rgbe.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.3.0.0] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
Does anyone know what it could be?
Based on what I'm reading here, I'm inclined to think that OpenCV is having issues on the AV codec for it's internal HighGUI library.
Are you using parallel builds with make? That might explain it -- this step could be dependent on another step that has not been completed yet.
hzheng_449
30-11-2013, 23:39
While compiling OpenCV, at 20%, I got this error:
[ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
[ 20%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/rgbe.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.3.0.0] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
Does anyone know what it could be?
I'm pretty sure I got a similar build error when I was installing openCV(which was around September). Hopefully Brennon's suggestion works, if not try building an older version of openCV or do the "lazy" thing and apt-get the library (which is what I ended up doing).
faust1706
01-12-2013, 00:16
Since you said you were going to switch to ubuntu...here is the "master list" a mentor and I came up with 2 years ago:
sudo apt-get install synaptic
sudo apt-get update
*sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui
*sudo apt-get install qtcreator
sudo su
sudo apt-get install build-essential
sudo apt-get install libavformat-dev
sudo apt-get install ffmpeg
sudo apt-get install libcv2.3 libcvaux2.3 libhighgui2.3 python-opencv opencv-doc libcv-dev libcvaux-dev libhighgui-dev
**apt-get install freenect
*install qt creator, an IDE (integrated development platform)
**for kinect
we used these exact steps for our O-Droid XUs we got 2 weeks ago and all are running vision programs without any problems.
I did try to build many of the things like x264 and ffmpeg, and whatever I couldn't find in the apt repository, myself, from the git code! I think that I may be using too current of a code! That could be why I am having many of these problems!
I think it would be wise for someone (maybe me), to create an install script, to install every package from Apt, and then download source from git to build! ;)
brennonbrimhall
01-12-2013, 13:21
I did try to build many of the things like x264 and ffmpeg, and whatever I couldn't find in the apt repository, myself, from the git code! I think that I may be using too current of a code!
Might be a bit late, but this (http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html) is the official documentation from OpenCV with regards to building on Linux. Unless you plan on working on OpenCV itself, I'd stick with version 2.4.7, which is the latest stable version.
EDIT: As of 11/11/13, the latest version of OpenCV is 2.4.7.
It's not too late. I just need to redownload OpenCV and reconfigure it. Just a half hour, maybe. I have succeeded at building OpenCV from git before, but I do not know what is different this time. Let me make sure that I have properly installed LibAVCodec!
BTW, Brennon Brimhall, Thanks for the quick reply!
EDIT:
I just booted Ubuntu and checked the libavcodec installation status and found out that it wasn't properly installed. I forgot libavcodec-dev, but installed libavcodec-53! Now, let me retry the build, and hopefully I won't encounter any problems! :D
The build is still failing continuously. What do I do? I have uploaded a txt file with the output, created by make | tee dev_build.txt
I have tried re-installing libavcodec-dev libavcodec53 libavcodec-extra-53 but the problem persists. Should I compile it myself, or should I get a different mirror, update my system, or am I downloading a completely wrong package?
UPDATE:
I am compiling the code in the fashion that Brennon suggested, downloading the latest stable build from SourceForge (http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.7/opencv-2.4.7.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fproj ects%2Fopencvlibrary%2F&ts=1385933735&use_mirror=softlayer-dal). Currently it is compiling. I will include a build log, build_log.txt.
Thanks for your help
It seems as though maybe the libavcodec package may be broken :(. That is what is stopping me from having a complete build!
Darn it...the edit button is broken :(
I have gotten OpenCV installed. I just used "apt-get install libopencv-dev". Hopefully that works.
I have one problem now:
I do not trust the Windows version of OpenCV. I had a working install, which got corrupted when I ran sample code! My team wants to stick with Windows, because that is the OS that everyone is familiar with and the Driver Station resides on. How should I use OpenCV? We are using Java, though I am sure that the language shouldn't make any difference. Should I run VIrtualBox on the DS, or should I get another DS laptop (We have a couple) to boot Ubuntu (Or maybe Debian, to make the install lighter), to run OpenCV? That laptop can also become the network robot coprocessor!
virtuald
02-12-2013, 23:09
Building OpenCV on Windows is pretty straightforward if you have Visual Studio installed. Just run cmake and then compile the sln files.
We had delay issues connecting FFMPEG to the camera, and had to compile a custom version of it to make it work. I was able to use the FFMPEG build instructions found in the OpenCV source code to build the DLL successfully using MinGW.
Check out the following links for the bug report:
http://code.opencv.org/issues/2877
https://trac.ffmpeg.org/ticket/2343
Installing in Windows is quite straightforward. However, I find it hard to trust the install. It works at first, but breaks when you are in the middle of something big! :(. At least, this is what happened to my installation! That's why I am interested in Linux!
Invictus3593
03-12-2013, 09:08
The full installation (http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html) crashes on you? I've never had problems with that... maybe try a reinstallation? Your download could've been interrupted at the very end and some file could be corrupt or something, as the repository is "quite a heavy download."
Also, make sure you're running a legal copy of Windows; I've found trouble installing many things if not with a legal copy because of some missing components. :rolleyes:
The full installation (http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html) crashes on you? I've never had problems with that... maybe try a reinstallation? Your download could've been interrupted at the very end and some file could be corrupt or something, as the repository is "quite a heavy download."
Also, make sure you're running a legal copy of Windows; I've found trouble installing many things if not with a legal copy because of some missing components. :rolleyes:
My copy of Windows is genuine. It is OEM! I doubt it was the download because it worked before. However, when I ran some code, it crashed and OpenCV got corrupt. I was running OpenCV 2.4.3, because that was the version where I could find max info about! BTW, I am using 7, and VS C++ Express 2010. However, I can use VS pro if you guys suggest it!
brennonbrimhall
03-12-2013, 12:48
Installing in Windows is quite straightforward. However, I find it hard to trust the install. It works at first, but breaks when you are in the middle of something big! :(. At least, this is what happened to my installation! That's why I am interested in Linux!
Unless you're running a "bleeding edge" version of OpenCV (e.g., you cloned the git repository and compiled straight from source), there shouldn't be a reason why the OpenCV library crashed on you.
I would suspect instead that you had a misconfigured development environment (not having all the compiled binaries in your PATH, for example), a bad build, a corrupted source tree, etc., assuming you used a stable version of OpenCV.
You concern me when your solution to your problem is to install OpenCV on Linux and run that on the Driver Station. Virtualization is very resource-intensive, and I would recommend not doing that on the master controller for the robot, especially with something running on VirtualBox as computationally intensive as computer vision. Instead, I would go back a few steps and look for the root cause of failure, and look at the documentation that OpenCV has on their website and fix your original Windows build. Just my $0.02.
And one more suggestion: I would consider using OpenCV's Q&A site (http://answers.opencv.org/questions/), where OpenCV experts are able to give you far better advice than me (and probably the rest of the CD community).
No. I used an OpenCV build that I found online, 2.4.3! I am pretty sure that isn't the problem. Also, I did mess around with the configuration a lot, to make it work. It worked until the binaries got corrupted!
brennonbrimhall
04-12-2013, 08:23
No. I used an OpenCV build that I found online, 2.4.3! I am pretty sure that isn't the problem. Also, I did mess around with the configuration a lot, to make it work. It worked until the binaries got corrupted!
If the binaries are corrupted, that would most likely be due to a faulty download or physical hardware failure.
Just last night, I installed the OpenCV 2.4.7 Java binaries on my machine and was doing some facial recognition stuff from Eclipse. While I wasn't using the C++ interface, it seemed that the binaries were right there with the self-extracting archive.
I'm still confused as to how the binaries were corrupted, or why you were led to believe that the corruption of your binaries was related to Windows. There should be a reliability decrease if you use OpenCV on virtualized Linux on the same machine, not a reliability gain.
Anyways, I am now interested in using Apt for the installation. It seems a lot easier to do. After installing the Apt version, I was unable to compile anything. What did I do wrong? If anyone would like to help me, I might set up a skype or RDP connection!
faust1706
06-12-2013, 10:30
Anyways, I am now interested in using Apt for the installation. It seems a lot easier to do. After installing the Apt version, I was unable to compile anything. What did I do wrong? If anyone would like to help me, I might set up a skype or RDP connection!
I posted the apt-gets in an earlier comment. I have personally used this list to install opencv 5 times, and other students and mentors on the team have used it over ten times as a collection without any problems.
It is also explained on our team's website:
http://ratchetrockers1706.org/vision-setup/
We are working on a script that will install it all, and compile some of our vision code. Hopefully it will be up on our website before build season starts, so all you'll have to do is click run, wait a couple minutes, then opencv will be installed!
If you have any questions, don't be afraid to ask.
I am actually interested in creating a bash script that will download most of the things using git, and compiles it by itself. That would be nice. However, that will only be possible after I get OpenCV running myself!
That tutorial that you forwarded to me seems legit. :cool:
I think I will reinstall Ubuntu (or try in virtulbox) and then try this to make sure there is maximum consistency! I wish I had more Raspberry Pis! :(
Greg McKaskle
07-12-2013, 07:10
How do you know the binaries were corrupt? Also, are you sure that the crash was due to the library and not something else, like the test program?
Greg McKaskle
Visual Studio told me that they were corrupt and unreadable, and if I continued, my computer crashed!
Greg McKaskle
07-12-2013, 19:12
Do you have more specifics on the message? For instance, if Visual Studio told you that memory was corrupted at a stack crawl including OpenCV, and then you continued, you would indeed crash, but that has nothing to do with the library or DLL on disk. If you think the library is corrupt, something like nm or ld with some options would probably be the right tool to determine if it is corrupt and what is wrong.
I've rarely seen a corrupted library. The instances I saw it were in the Win31 and Win95 days and the disk sector information was already bad when the library was installed. My guess is that you do not need to reinstall SW, but instead need to correct the usage of the library functions.
Greg McKaskle
I know it was corrupt because it started working as soon as I copied new binaries into the installation folder!
Greg McKaskle
08-12-2013, 07:15
That's one possibility, but another is that the corruption is based on memory locations. It is transient and may not happen every time you run. Memory corruptions can be difficult to understand and track down, especially when they deal with heap allocations. Images are big enough that they are almost never stack based.
I could be totally wrong, and you do not need to prove to me that the libraries were corrupted. I was just wanting to put a suggestion out there based on my experience.
Greg McKaskle
Yes. I agree. You most likely have more experience with this stuff (programming/electrical/build/etc.).
I am interested in Linux because there it is much more efficient than Windows. It is also a lot easier to get packages, like using Apt. I like a command interface more than a window system, the reason why I have terminal in my Ubuntu startup. Linux doesn't come with all the crapware that Windows typically comes with, meaning that I do not have to spend hours fishing out and cleaning my install. Also, as of what I have experienced, Windows is a resource hog. On my Laptop, I have an SSD. It takes Windows 10 seconds at least to boot, while Ubuntu can boot in two seconds! That isn't the big thing. I got my laptop because 6GB of RAM seemed like a lot. I was quite wrong with that because Windows takes 1GB of RAM, by itself. My Pi takes 128MB of RAM, running hundreds of processes in idle. Also, since my SSD is small (32GB), I have nothing installed, except 7-zip, FileZila and Notepad++.
My laptop has a very crappy processor (i3 2367 [1.4GHz]). With Windows, I can get a max of 8FPS running software like RoboRealm. I can get 32-60FPS on Linux. That is a big difference and when you are doing vision processing on a fast-moving thing, like a robot, you can expect decent lag, using Windows!
This is just what I have noticed and seen. You may have seen something different.
Does anyone have a link to some good source code to test OpenCV? I got OpenCV in QT Creator running, and I would like some code to test many functions of it!
Thanks, Hunter! I've finally gotten a working OpenCV install, I think. This is the reason why I use CD and not some other random forum out there!
Sorry for the triple post. I think it was kinda needed cause the posts are different from each other.
I was testing example code for OpenCV in QT Creator. It doesn't work for some reason. Here's the code. Can someone help me find out what happened? BTW, if someone wants to help me in real time, I can set up RDP!
Code: (typing without looking made me type Doec :D)
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
int main(int argc, char *argv[]) {
cvNamedWindow("MainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100,100);
cvWaitKey(0);
return 0;
}
Thanks for all of your help!
So I was able to compile an opencv program with g++, finally. However, using the command line like this can be a little painful. I followed Hunter's directions, and then used the directions here (https://help.ubuntu.com/community/OpenCV) to compile the code. How do I set up Netbeans to code on?
faust1706
22-12-2013, 03:10
Yash: on another note: Can you compile OpenNI and freenect now?
I haven't tested that yet, though I had noticed that the directions you gave me installed libfreenect. Libfreenect shouldn't be too much of a problem for me because I have even successfully compiled it before! How do I test libfreenect? I don't have and video-game controllers like the kinect or the PS Eye.
billbo911
26-01-2014, 19:40
I'm trying to use OpenCV on Ubuntu and program, in Python, circle detection for this years game, for obvious reasons ;).
I followed jfausts1706's install directions (http://www.chiefdelphi.com/forums/showpost.php?p=1307392&postcount=11) for installing OpenCV and it worked perfectly. I now have OpenCV 2.3.1 working! I can program in Python and have good success.
When using the HoughCircles function in OpenCV 2.3.1, I have discovered a HUGE PROBLEM. It works fine as long as a circle is detected. Once zero circles are detected, the program crashes. This is a known bug (https://code.ros.org/trac/opencv/ticket/1066).
I am trying to find a really good example of Python code that detects circles with OpenCV, and uses an alternate method that HoughCircles, but they are REALLY SCARCE.
Can someone either point me to a good resource for this code, or...... I may need to find a way to install a newer version of OpenCV. I am NOT a Linux wizard, but I can use the Synaptic Package Manager or a command line with apt-get if I know what steps to follow. Can anyone either walk me through the process or point me to a clearly and accurately written resource to guide me through the process?
otherguy
26-01-2014, 20:00
http://askubuntu.com/questions/334158/installing-opencv
sudo apt-get install libopencv-dev should get you the latest
billbo911
26-01-2014, 20:17
http://askubuntu.com/questions/334158/installing-opencv
should get you the latest
Yeah, that's exactly what I'm talking about. It installs OpenCV 2.3.1. As I mentioned, I already have OpenCV 2.3.1.
OpenCV 2.3.1 Is not the latest version.
It is starting to look like I'm going to go the "cmake" route, something I am utterly unfamiliar with. That's why I asked for guidance.
faust1706
26-01-2014, 20:23
Bill,
Have you tried a memory test for the storage device of houghcircles? My python knowledge is really weak, but I believe
if circles is not None:
would be a test to make sure that there are circles.
Or you could findcontours of the image, then check to see if there are contours, and if there are, apply houghcircles. Just some ideas.
billbo911
26-01-2014, 21:07
Bill,
Have you tried a memory test for the storage device of houghcircles? My python knowledge is really weak, but I believe
if circles is not None:
would be a test to make sure that there are circles.
Or you could findcontours of the image, then check to see if there are contours, and if there are, apply houghcircles. Just some ideas.
Now there's a thought! I'll try that next.
One problem so see in that is contours don't always indicate circles. So, the issue would still be there.
Either way, I'll give it a try.
faust1706
26-01-2014, 21:58
No, contours will not tell you whether there are circles or not, but it will tell you that there is readable data in your input image. Another route would be findcontours then approxpoly and if approxpoly outputs that it has 5 or more sides, call it a circle, or call fitelipse or minboundcircle on the output of contours.
I do not know anyone who has had success with houghcirlces. The math is clever, but it just does not seem to work.
I downloaded OpenCV and used ccmake to find out everything that OpenCV supports. I used apt-get to get each and every one of those (that I could find). That OpenCV build/install was beast because the feature set was past you expectations.
I found the problem that OpenCV requires you to manually play with pkg-config to work. I actually memorized the entire build process/apt-get process of installing OpenCV in both Linux and Windows, and now that I look at it, it is quite siimple.
I reinstalled the Operating System, Windows, and now OpenCV works like a charm. However, I get twice the performance in Ubuntu, with Nautilus/Unity. I get even a greater performance with Lubuntu.
I think now I need to get a Lubuntu install and hack it so the CPU governer is set at performance, basically "overclocking" my laptop. Before I do this, does anyone know if I can change the CPU governor on demand? It'd be nice to make the program to automatically set up performance while running, and set the FSB/Governor back to ondemand/power-saver on program exit.
So, finally, I have the install completed in Win7|8|8.1, Ubuntu 12.04/10|13.04/10 and Lubuntu 12.10, both running under Wubi.
The install under Linux:
apt-get install qtcreator libopencv-dev git pkg-config python-opencv
TO compile under linux:
apt-get install cmake-curses-gui build-essential cmake git
git clone <opencv git>
mkdir release&&cd release
ccmake ..
press configure (i think it is c)
note all the things it says possible to build and get what you want. enable those features and press g to generate
cmake ..
make -j <number of cores in system>
use the -j argument if you don't want the compile to use just ~30% processor and take a couple hours. That will multithread the compile
make install:deadhorse:
set up the ldconfig stuff. I can't recall how to do it, but google is nice. ldconfig -v should get it into pkg-config
enjoy
btw, fix any errors you get. they are easy to understand and you have google and CD
apt-get install qtcreator
^^don't do the compile unless you are a guru with linux/compiling large things!!!!!!!!!!!:deadhorse: :deadhorse:
I think I'll put more complete tutorials on my website when i have time. For now, this should be a start for most people who have a moderate experience with compiling stuff. For rookies/newbies, use apt-get because that is just 100x easier! if you want, i can use QEMU to generate RPi images with OpenCV, maybe even compiled!
Don't compile unless you need the latest software. You'll still get 2.4.2 via apt-get so most of the feature will be similar!
By the way, I am thinking about trying hough transforms to find the balls. The ball's location will be found and then go through BGR2RGB => BGR2HSV, or BGR2HSV, depending on the bll color you are looking for. BGR2RGB switches the color channels so red becomes blue and blue becomes red! That should work like a beast if hough transforms are any good.
billbo911
27-01-2014, 01:56
No, contours will not tell you whether there are circles or not, but it will tell you that there is readable data in your input image. Another route would be findcontours then approxpoly and if approxpoly outputs that it has 5 or more sides, call it a circle, or call fitelipse or minboundcircle on the output of contours....
OK, that is starting to work. I actually have something that is starting to work, or so it appears.
Part of the revelation that got me over the hump was that any function that starts with "cv2." just doesn't work well on my system, if at all. It must be the version of OpenCV I have, but as long as I stick to "cv." functions I should be fine. Now, if someone can explain that, and how to rectify it, I would be ALL EARS!
faust1706
27-01-2014, 18:29
Obligatory tutorial post about bounding rectangles and minenclosing circle for those who are interested:
http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html
Here is what I have done with these various methods:
fitelipse: http://www.chiefdelphi.com/media/photos/39015
bounding rectangle: http://www.chiefdelphi.com/media/photos/39264
approxpoly: http://www.chiefdelphi.com/media/photos/39147 (from the stl regional)
another approxpoly from 2012: http://www.chiefdelphi.com/media/photos/38819
Approxpoly is great at what it does, but it doesn't always return the proper corners, which is not ideal for doing a pose calculation to get distance in x y z and pitch roll yaw. To fix this, cornersubpix is used, which its whole existence is to refine corner locations. You give it where you think corners are, give it a matrix of pixels to look in around the corner(s) you gave it, and it outputs refined corner locations with subpixel accuracy. Tutorial:
http://docs.opencv.org/doc/tutorials/features2d/trackingmotion/corner_subpixeles/corner_subpixeles.html
LASTLY, to get an accurate center from find contours, apply a moment calculation so you have subpixel accuracy for the given contour:
http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/moments/moments.html
I am going to try to get OpenFrameworks to work, alongside OpenCV. I guess that it would give me access to a couple more features!
The problem is that the installation instructions are how to install VS, not OF! :( :confused: :yikes:
billbo911
27-01-2014, 23:14
Obligatory tutorial post about bounding rectangles and minenclosing circle for those who are interested:
http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html
Here is what I have done with these various methods:
fitelipse: http://www.chiefdelphi.com/media/photos/39015
bounding rectangle: http://www.chiefdelphi.com/media/photos/39264
approxpoly: http://www.chiefdelphi.com/media/photos/39147 (from the stl regional)
another approxpoly from 2012: http://www.chiefdelphi.com/media/photos/38819
Approxpoly is great at what it does, but it doesn't always return the proper corners, which is not ideal for doing a pose calculation to get distance in x y z and pitch roll yaw. To fix this, cornersubpix is used, which its whole existence is to refine corner locations. You give it where you think corners are, give it a matrix of pixels to look in around the corner(s) you gave it, and it outputs refined corner locations with subpixel accuracy. Tutorial:
http://docs.opencv.org/doc/tutorials/features2d/trackingmotion/corner_subpixeles/corner_subpixeles.html
LASTLY, to get an accurate center from find contours, apply a moment calculation so you have subpixel accuracy for the given contour:
http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/moments/moments.html
Thanks for all the pointers and links!
The only issue is, we are using Python and most of the tutorials available are for C++. There is no easy translation from one to the other.
So, I'll keep pluggin' away.
I need to learn how to use polygon functions to find balls! I tried hough-transforms, but for a function deemed as "very powerful" I was very disappointed. I was only able to detect a CD, and even that needed to be in an exact environment for the processing/detection to be successful/trustworthy!
faust1706
28-01-2014, 19:44
I need to learn how to use polygon functions to find balls! I tried hough-transforms, but for a function deemed as "very powerful" I was very disappointed. I was only able to detect a CD, and even that needed to be in an exact environment for the processing/detection to be successful/trustworthy!
Here you go: http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?hig hlight=minarearect#minarearect
functions to look at:
findcontours (this is a mus)
with the output you could feed it into:
Approxpoly
fitelipse
boundingrect
contourarea to eliminate noise that passed your thresholds and morphological operations (aka erode and dilate)
iscontourconvex - this will return contours with corners going outward. A shape that would not pass this for example is the number 7.
minarearect is like boundingrectangle, but it can be rotated. I apply this when the static and dynamic target combine when I am 30+ feet away and check the "slope" of the box to test which corner I am looking at. The right corner will be positive and the left will be negative.
minenclosingcircle: it is sort of like fitelispse, but it will return an actual circle. A ball will be circular no matter what angle you look at. A frisbee will not. I am using this function for ball tracking this year.
It really comes down to pick your poison. I know there are other methods for object tracking (cough cough canny), but this all have example programs on them.
Honourable reference: goodfeaturestotrack.
Strange thing is I got houghllines and houghlinesp to work over the summer yet houghcircle just doesn't work. I'll see what I can do to fix it after this season.
I have personally gotten all of these functions I have referenced to work, if anyone has questions, shoot me a pm.
I think it could be my OpenCV version that sucks. I guess that if I migrate back to Windows, things will move much more smoothely! I really think it is a pain switching platforms, especially from Ubuntu to Windows because I first need to copy the files, and manually configure the compiler. I wonder if it is possible to get pkg-config-like library manager for windows so I don't need to spend half an hour creating a project!
If anyone's interested, I came up with this program:
http://www.youtube.com/watch?v=N2jXXdJkp2w
billbo911
28-01-2014, 22:40
If anyone's interested, I came up with this program:
http://www.youtube.com/watch?v=N2jXXdJkp2w
Looks like Canny!
I was using that for generating a bin file for FindContours. Let's just say, not a good idea. I'm back to HSV processing and I'm doing way better now!
billbo911
29-01-2014, 15:31
OK, I'm feeling really dense right now.
I've gotten my detection code for the balls to reliable identify the balls and place the location parameters into an array. I am using cv.MinEnclosingCircle to generate the target location values.
The issue is, I can't figure out how to get the data out of the array for displaying or using to move the robot.
The format of the data is as follows form a "print Balls" command:
[(1, (101.5, 137.5), 76.88045398)]
I know the 101.5 is the center "X" value, the 137.5 is the center "Y" and the 76.88... is the Radius.
When I try something like
(x,y) = Balls [1]
print x
I get the error message "IndexError: list index is out of range"
What simple Python command let's me parse this info out?
(As you can tell, I'm still learning Python.)
sparkytwd
29-01-2014, 15:37
Try Balls[0][1]
[(1, (101.5, 137.5), 76.88045398)]
means a list with 1 element that is a tuple containing 3 elements
billbo911
29-01-2014, 16:05
Try Balls[0][1]
means a list with 1 element that is a tuple containing 3 elements
OK, that kind of works,
x = Balls[0][1]
print x gives me
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5) and continues scrolling as the code is looping, as expected. Then suddenly it crashes out and gives the same "index out of range message.
So, two steps forward, one back.
How would I parse out "x" and "y" from this.
Next, any idea why it crashes out?
Please ignore the "Crashing"
I figured out it was crashing out when it didn't see any circles. I adjusted my code to prevent this. So, now I would just like to know how to parse out the three values separately.
faust1706
29-01-2014, 17:00
OK, I'm feeling really dense right now.
I've gotten my detection code for the balls to reliable identify the balls and place the location parameters into an array. I am using cv.MinEnclosingCircle to generate the target location values.
The issue is, I can't figure out how to get the data out of the array for displaying or using to move the robot.
The format of the data is as follows form a "print Balls" command:
[(1, (101.5, 137.5), 76.88045398)]
I know the 101.5 is the center "X" value, the 137.5 is the center "Y" and the 76.88... is the Radius.
When I try something like
(x,y) = Balls [1]
print xI get the error message "IndexError: list index is out of range"
What simple Python command let's me parse this info out?
(As you can tell, I'm still learning Python.)
Oh boy. I only started learning python 2 weeks ago. Um...try Balls[1][1] for x and [1][2] for y?
billbo911
29-01-2014, 17:29
OK, I'm feeling really dense right now.
I've gotten my detection code for the balls to reliable identify the balls and place the location parameters into an array. I am using cv.MinEnclosingCircle to generate the target location values.
The issue is, I can't figure out how to get the data out of the array for displaying or using to move the robot.
The format of the data is as follows form a "print Balls" command:
[(1, (101.5, 137.5), 76.88045398)]
I know the 101.5 is the center "X" value, the 137.5 is the center "Y" and the 76.88... is the Radius.
When I try something like
(x,y) = Balls [1]
print x
I get the error message "IndexError: list index is out of range"
What simple Python command let's me parse this info out?
(As you can tell, I'm still learning Python.)
OK, I just had a conversation with my son. Why I didn't do this earlier I can't explain.
He tells me that if I want the "x" , "y" and radius values, I should use:
x = Balls[0][1][0]
y = Balls [0][1][1]
radius = Balls [0][2]
I'll check this out when I get to the school in a couple hours and update this thread when I confirm it, or not.
OK, that kind of works,
x = Balls[0][1]
print x gives me
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5)
(101.5, 137.5) and continues scrolling as the code is looping, as expected. Then suddenly it crashes out and gives the same "index out of range message.
So, two steps forward, one back.
How would I parse out "x" and "y" from this.
Next, any idea why it crashes out?
Please ignore the "Crashing"
I figured out it was crashing out when it didn't see any circles. I adjusted my code to prevent this. So, now I would just like to know how to parse out the three values separately.
I think you might be having some sort of an overflow. If you can give us (or pm us) some code, we could help you debug the problem.
UPDATE****
I just googled and I think you may have messed up with some X and Y variables, causing the canvas size to be a tad small, triggering this error!
That's something you may want to look at!
billbo911
29-01-2014, 20:18
OK, I just had a conversation with my son. Why I didn't do this earlier I can't explain.
He tells me that if I want the "x" , "y" and radius values, I should use:
x = Balls[0][1][0]
y = Balls [0][1][1]
radius = Balls [0][2]
I'll check this out when I get to the school in a couple hours and update this thread when I confirm it, or not.
I can confirm 100%, that the above parsing works perfectly to extract X, Y, and Radius from the output of MinEnclosingCircle.
I think you might be having some sort of an overflow. If you can give us (or pm us) some code, we could help you debug the problem.
UPDATE****
I just googled and I think you may have messed up with some X and Y variables, causing the canvas size to be a tad small, triggering this error!
That's something you may want to look at!
Nope, the crash was caused by trying to parse out values from an empty array/tuple. If there are no values there and you try to parse it, the structure of the array is different from the structure of the parse, and thus it crashes!
Our code is now working and tracking just how we want it to.
Great job, and I hope we are alliances if we reach the competitions and we win!
Team 1706's robot is more like a 1-man team! I'd be surprised if the other teams just stood at the corner, out of the way, and 1706's bot still beats the other alliance by at least a scale of 10 :D
1706: Please put a go-pro on your bot. I want to see some FPV views from the robot! If seems like some hardware!
Yeah, that's exactly what I'm talking about. It installs OpenCV 2.3.1. As I mentioned, I already have OpenCV 2.3.1.
OpenCV 2.3.1 Is not the latest version.
It is starting to look like I'm going to go the "cmake" route, something I am utterly unfamiliar with. That's why I asked for guidance.
get ccmake. run ccmake .. instead of cmake .. that will give a list of features to enable. find all the features you want and get the dependencies! Then, run cmake .. and make -j [#cores in computer]!
billbo911
12-02-2014, 20:38
get ccmake. run ccmake .. instead of cmake .. that will give a list of features to enable. find all the features you want and get the dependencies! Then, run cmake .. and make -j [#cores in computer]!
Wow, I almost understood that. :eek:
Right now we have working code, so we are taking the approach: "if it aint broke....."
That said, I definitely will be looking to upgrade from 2.3.1 after this season is done. I have a few reason, not the least of which is I want to be able to use OpenCV with both a web cam, or two, and the network cam. Currently the network side is giving me errors that, from some quick searches, can be resolved with a newer version of OpenCV.
I also have some working code that works so well that when I showed it to the team for the first time, they thought i was doing impossible things!
Enough of the bragging :D.
My work ethics (and my inner hacker) tells me that if the code works, save a copy of it and fix it (add features) until it stops working! I started with OpenCV from APT then compiled and installed my own opencv (this time i used common sense instead of tutorials). Then, I got the windows version working and then working alongside with the ds. the best thing is that my code will work with linux/unix/windows!
Now, I need to figure out the socket communication!
I also have some working code that works so well that when I showed it to the team for the first time, they thought i was doing impossible things!
Enough of the bragging :D.
My work ethics (and my inner hacker) tells me that if the code works, save a copy of it and fix it (add features) until it stops working! I started with OpenCV from APT then compiled and installed my own opencv (this time i used common sense instead of tutorials). Then, I got the windows version working and then working alongside with the ds. the best thing is that my code will work with linux/unix/windows!
Now, I need to figure out the socket communication!
Now, I'm working on a vision whitepaper/combo. Here's what I have so far. It's a work in progress. Neg me if you hate it, up me if you like it! ;)
(Where do I upload PDFs? the attachments bar doesn't like it!)
http://devstuff.no-ip.biz:890/cdn/uploads/Vision%20Whitepaper.pdf
billbo911
12-02-2014, 21:35
.....
(Where do I upload PDFs? the attachments bar doesn't like it!)
http://devstuff.no-ip.biz:890/cdn/uploads/Vision%20Whitepaper.pdf
Uploaded as a white paper, then put a link to it on this post.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.