Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Installing OpenCV (http://www.chiefdelphi.com/forums/showthread.php?t=122522)

faust1706 27-01-2014 18:29

Re: Installing OpenCV
 
Obligatory tutorial post about bounding rectangles and minenclosing circle for those who are interested:

http://docs.opencv.org/doc/tutorials...s_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...ubpixeles.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...s/moments.html

yash101 27-01-2014 18:57

Re: Installing OpenCV
 
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

Re: Installing OpenCV
 
Quote:

Originally Posted by faust1706 (Post 1333325)
Obligatory tutorial post about bounding rectangles and minenclosing circle for those who are interested:

http://docs.opencv.org/doc/tutorials...s_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...ubpixeles.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...s/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.

yash101 28-01-2014 19:12

Re: Installing OpenCV
 
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

Re: Installing OpenCV
 
Quote:

Originally Posted by yash101 (Post 1333848)
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/imgpr...ct#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.

yash101 28-01-2014 20:16

Re: Installing OpenCV
 
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!

yash101 28-01-2014 22:24

Re: Installing OpenCV
 
If anyone's interested, I came up with this program:
http://www.youtube.com/watch?v=N2jXXdJkp2w

billbo911 28-01-2014 22:40

Re: Installing OpenCV
 
Quote:

Originally Posted by yash101 (Post 1333965)
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

Re: Installing OpenCV
 
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
Code:

(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

Re: Installing OpenCV
 
Try Balls[0][1]

Quote:

Originally Posted by billbo911 (Post 1334338)
[(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

Re: Installing OpenCV
 
Quote:

Originally Posted by sparkytwd (Post 1334344)
Try Balls[0][1]



means a list with 1 element that is a tuple containing 3 elements

OK, that kind of works,
Code:

x = Balls[0][1]
print x

gives me

Code:

(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

Re: Installing OpenCV
 
Quote:

Originally Posted by billbo911 (Post 1334338)
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
Code:

(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.)

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

Re: Installing OpenCV
 
Quote:

Originally Posted by billbo911 (Post 1334338)
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
Code:

(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:
Code:

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.

yash101 29-01-2014 20:01

Re: Installing OpenCV
 
Quote:

Originally Posted by billbo911 (Post 1334355)
OK, that kind of works,
Code:

x = Balls[0][1]
print x

gives me

Code:

(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

Re: Installing OpenCV
 
Quote:

Originally Posted by billbo911 (Post 1334388)
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:
Code:

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.

Quote:

Originally Posted by yash101 (Post 1334472)
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.


All times are GMT -5. The time now is 22:45.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi