Opencv Basics - Sources for beginners

Hello!

I’ve bought the Opencv book recently and made some little examples for some simple CV features that wasn’t in the ofxOpenCv addon :
[attachment=0:3pb9974z]OPENCVBASICS.zip[/attachment:3pb9974z]

This forum rocks, and I’ve been using it a lot recently and most of the time I quickly found the solutions I were looking for. SO here is my first small contribution to the forum.

It’s a small collections of OF apps showing theses cv features and filters: camShift, Canny, FeatureTracking, GoodFeaturesToTrack, HaarClassifier, HoughCircles, HoughLines, Invert, Laplace, OpticalFlowPyrLK, Sobel, TemplateMatching, XorS, …

The archive contains VisualStudio 2008 projects but if you are using another IDE, I guess you just need to copy the ofxOpenCvExample and then paste the testApp.cpp, testApp.h, and main.h files inside the src folder.

Hope the beginners will find the stuffs that I missed when I started computer vision.

I’m learning C++ for 4 months now, so the code might not be the best you’ll find here, but well! it is working! Most of the sources were adapted from the book itself.

Thank you all for this forum, and one more time thank you to all the developers behind OpenFrameworks!

Simon.

OPENCVBASICS.zip

it’s asking for glui.h?

thanks,
alp

Really?

I don’t remember using glui in those projects… can you tell me in wich one?

Anyway you can just remove every dependencies to glui.h or start with a new “opencvexample” project…

Hi,

Is the Open CV book you mention the O’reilly Book?

Thanks

Greg

Yes! It is!
A nice book written by some of the creators of OpenCv!

I have been trying to run these great examples, but even after properly linking (getting rid of all te file not found errors) it is saying “Symbols not found” in refrence to things like ofxCvGreyscaleImage and ofxCvImage
im a bit new at getting these things running and would appreciate any assistance.

“ofxCvImage::allocate(int, int)”, referenced from:
“ofxCvColorImage::ofxCvColorImage()”, referenced from:
“ofxCvColorImage::setFromPixels(unsigned char*, int, int)”, referenced from:

I have been trying to run these great examples, but even after properly linking (getting rid of all te file not found errors) it is saying “Symbols not found” in refrence to things like ofxCvGreyscaleImage and ofxCvImage
im a bit new at getting these things running and would appreciate any assistance.

“ofxCvImage::allocate(int, int)”, referenced from:
“ofxCvColorImage::ofxCvColorImage()”, referenced from:
“ofxCvColorImage::setFromPixels(unsigned char*, int, int)”, referenced from:

I think you’ve gotten the include paths right, but you still need to add the source code from the addon:

addons/ofxOpenCv/src

ie, it’s able to find the .h files, but when linking it can’t find .o files that come from compiling .cpp.

a few things that can help:

a) look at the addon example in apps/addonsExamples/opencvexample you can duplicate this project file, or open it up to see what the differences between yours and it are.

b) look at the install.xml in the addon folder, that should have a list of the files / include paths and linking you need to add for your project.

I hope that helps !

take care,
zach

I’m also having trouble getting these to compile, I get a collection of errors shown in the attached screenshot, they seem to be related to the PS3 cam,

I’ve included ofxPS3.h & ofxPS3.cpp (which I downloaded here http://nuicode.svnrepository.com/svn/tb-…-ns/ofxPS3/).

I also had to import Windows.h from /Developer/SDKs/MacOSX10.5.sdk/Developer/Headers/FlatCarbon

Have a missed something ?

![](http://forum.openframeworks.cc/uploads/default/547/Screen shot 2010-01-14 at 00.11.42.png)

Hey!

You won’t be able to use ofxPS3 on your mac because it’s a windows only library!

I’m sorry for all this problems, I should have notice that! As soon as I get some time, I will clean all this examples…

Right now, the easiest thing you can do, is copy and paste the opencvExample, rename it and then copy and paste all the code in the testApp that is not related to how you capture the image (don’t copy stuffs about ps3). You should be able to make it work with the ofVideoGrabber or ofVideoPlayer…

Hope it helps!

I been trying to get this to work by copying your code into the openCV example. Not having any luck. The program compiles, but notes a cvError. I am wondering if this has something to do with this chunk of code…

  
image = cvCreateImage( cvGetSize(colorImg.getCvImage()), 8, 3 );  
	image->origin = colorImg.getCvImage()->origin;  
	hsv = cvCreateImage( cvGetSize(colorImg.getCvImage()), 8, 3 );  
	hue = cvCreateImage( cvGetSize(colorImg.getCvImage()), 8, 1 );  
	mask = cvCreateImage( cvGetSize(colorImg.getCvImage()), 8, 1 );  
	backproject = cvCreateImage( cvGetSize(colorImg.getCvImage()), 8, 1 );  
	hist = cvCreateHist( 1, &hdims, CV_HIST_ARRAY, &hranges, 1 );  
	histimg = cvCreateImage( cvSize(320,200), 8, 3 );  
	cvZero( histimg );  

Are there missing refecences with cvGetSize?

Thanks for any help as always…

Ian

Well, if colorImg is allocated correctly, I don’t see where the code could be wrong!
Wish example is this? Camshift? Wish version of OF are you using?

Thanks for sharing those examples!

Really helped me out understanding the different techniques! However, the laplace example is not working. Check this [attachment=0:2z5vktk8]Capture.JPG[/attachment:2z5vktk8].

I tried converting it but my knowledge is too limited I guess. Any idea/help?

Cheers

I don’t know why it’s not working anymore, maybe there was some changes in the opencv images in the new addon release!

Anyway this message says that you are trying to use wrong images format with the laplacian filter!
Actually every ofxCvImage has a ipldepth variable that is either IPL_DEPTH_8U, IPL_DEPTH_16U or IPL_DEPTH_32F, … this is actually the internal image format of opencv.

Now to come back to the laplacian filter, the method takes 3 arguments; The two first are the input and output image of the filter:

  
  
   cvLaplace(inputImage.getCvImage(), outputImage.getCvImage(), 0);  
  

And this error message is trying to say that the filter only supports this convertions:

IPL_DEPTH_8U -> IPL_DEPTH_16S
IPL_DEPTH_8U -> IPL_DEPTH_32F
IPL_DEPTH_32F -> IPL_DEPTH_32F

So if you use ofxOpenCv addon this mean:

ofxCvGrayScaleImage -> ofxCvFloatImage

  
  
   ofxCvGrayScaleImage inputImage;  
   ofxCvFloatImage outputImage;  
  

I hope this makes sense for you(and that i did not make mistakes)!

ps: ofxCvGrayScaleImage = IPL_DEPTH_8U
ofxCvColorImage = IPL_DEPTH_8U
ofxCvFloatImage = IPL_DEPTH_32F

Hey!

Thanks! I figured that part out, but I reversed the two values… it was very late! haha
I have that part working now.

Would anybody know how to do something similar for cvDistTransform? My goal with these functions is to get skeletonization working. Check this link: http://pinkjade8848.spaces.live.com/blog/cns!E4159959CD42C507!195.entry

Any thoughts?

Cheers

Hi, I’m having some problems running you’re camshift example.

CvScalar testApp::hsv2rgb( float hue ); in testApp.h

this returns me an error

can explain me whats going on here

thanks

E

Hi ,
Thanks for publish all the examples.
I was using the example of pryramildal optical flow and I guess I found a concept error using it. Have more meaning use the prev frame and actual frame as the name says.

So to fix this, check the last part of the update testApp,

prevGrayImage = grayImage;
grayImage = colorImg;
grayImage.mirror(false, true);

}
if(opticalFlow)
{
cvCalcOpticalFlowPyrLK( prevGrayImage.getCvImage(), grayImage.getCvImage(), prev_pyramid, pyramid, points[1], points[0], count, cvSize(win_size, win_size), 3, status, features_errors, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), flags );
//flags |= CV_LKFLOW_PYR_A_READY;
CvPoint2D32f *swap_points;
CV_SWAP( points[0], points[1], swap_points );
CV_SWAP( prev_pyramid, pyramid, swap_temp );
}

and modify it to use the prevGrayImage as this:

  
  
		grayImage = colorImg;  
		grayImage.mirror(false, true);  
		  
		if(opticalFlow)  
		{  
			cvCalcOpticalFlowPyrLK( prevGrayImage.getCvImage(), grayImage.getCvImage(), prev_pyramid, pyramid, points[1], points[0], count, cvSize(win_size, win_size), 3, status, features_errors, cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), flags );  
                        flags |= CV_LKFLOW_PYR_A_READY;  
			  
			CvPoint2D32f *swap_points;  
			CV_SWAP( points[0], points[1], swap_points );  
			CV_SWAP( prev_pyramid, pyramid, swap_temp );  
			  
		}  
		  
		//save the last grayImage  
		prevGrayImage = grayImage;  
  

Hope this help!
Cheers