Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Tracking Rectangles (http://www.chiefdelphi.com/forums/showthread.php?t=99424)

tomy 09-01-2012 23:25

Re: Tracking Rectangles
 
But question is still how do you get the robot to track the rectangle like it would with a circle?

JewishDan18 10-01-2012 00:38

Re: Tracking Rectangles
 
Quote:

Originally Posted by mikegrundvig (Post 1101272)
The whitepaper is extremely useful but the part I needed help with is actually what's glossed over the most. My understanding is that it's fully possible to determine both angle and distance from the target by the skew of the rectangle and the size. Here is a quote from the whitepaper:

"Shown to the right, the contours are fit with lines, and with some work, it is possible to identify the shared points and reconstruct the quadrilateral and therefore the perspective rectangle"

Except it stops there. Have any other reading or direction you can send us to take this the rest of the way? I'd really like our bot to be able to find it's location on the floor with the vision targets and unless we are straight-on, this is going to require handling the angle. Thanks!

-Mike

This varied depending on which language you use. If you aren't using Java, you should have access to a "convex hull" function, and a "find edge" function, which should do what you want. I haven't tested this yet, as I am using Java and do not have these functions. I'm working on getting them implemented in Java, but I have bigger fish to fry at the moment.

In theory, the bounding rectangle should be enough, if you put your camera as high as possible, and are willing to tolerate a little error. The height would tell you how far away you are, and the width, after accounting for the height, would tell you how far "off center" you are, giving you your position in polar form relative to the target. The error would be greater the further off center you are (since the perspective transformation makes the rectangle taller than it should be), but I would need to test to see if it is a significant amount.

Greg McKaskle 10-01-2012 11:58

Re: Tracking Rectangles
 
1 Attachment(s)
Quote:

Originally Posted by mikegrundvig (Post 1101272)
The whitepaper is extremely useful ...

Except it stops there. Have any other reading or direction you can send us to take this the rest of the way? I'd really like our bot to be able to find it's location on the floor with the vision targets and unless we are straight-on, this is going to require handling the angle. Thanks!

-Mike

There are a number of approaches, but I'll show the one that I would use -- not in code, but as an example. I'm also making a few simplifications to get things started -- notably, I'm often assuming that the camera and target are in the same vertical plane.

1. I open up the image shown in the paper into Vision Assistant (the one with the perspective distortion).
2. Use the third tool, the Measure tool to determine the lengths of the left and right vertical edges of the reflective strip. I measure 100 pixels and 134 pixels.

First image shows the measurements in red and green.

Since the edges are different pixel sizes, they are clearly different distances from the camera, but in the real-world, both are 18" long. The image is 320x240 pixels in size.

The FOV height where the red and green lines are drawn are found using ...

240 / 100 x 18" -> 43.2" for green,
and
240 / 134 x 18" -> 32.2" for red.

These may seem odd at first, but it is stating that if a tape measure were in the photo where the green line is drawn, taped to the backboard, you would see that from top to bottom in the camera photo, 43.2 inches would be visible on the left/green side, and since the red is closer, only 32.2 inches would be visible.

Next find the distance to the lines using theta of 47 degrees for the M1011...
(43.2 / 2) / tan( theta / 2) -> 49.7"
and
(32.2 / 2 ) / tan( theta / 2) -> 37.0"

This says that if you were to stretch a tape measure from the camera lens to to green line, it would read 49.7 inches, and to the red line would read 37 inches.

These measurements form two edges of a triangle from the camera to the red line and from the camera to the green line, and the third is the width of the retro-reflective rectangle, or 24". Note that this is not typically a right triangle.

I think the next step would depend on how you intend to shoot. One team may want to solve for the center of the hoop, another may want to solve for the center of the rectangle.

If you would like to measure the angles of the rectangle described above, you may want to look up the law of cosines. It will allow you to solve for any of the unknown angles.

I'd encourage you to place yardsticks or tape measures on your backboard and walk to different locations on the field and capture photos through your camera. You can then do similar calculations by hand or with your program. You can then calculate many of the different unknown values and determine which are useful for determining a shooting solution.

As with the white paper, this is not intended to be a final solution, but a starting point. Feel free to ask followup questions or pose other approaches.

Greg McKaskle

mikegrundvig 10-01-2012 12:38

Re: Tracking Rectangles
 
This is incredibly helpful - I have no idea why the idea to use the camera as part of a triangle didn't come to mind but it was the key piece I was missing. Thanks much!

-Mike

basicxman 11-01-2012 12:55

Re: Tracking Rectangles
 
Quote:

Originally Posted by Greg McKaskle (Post 1101535)
image shown in the paper into Vision Assistant

Would you be able to provide some raw images of the hoops through the Axis camera?

Greg McKaskle 11-01-2012 21:06

Re: Tracking Rectangles
 
Perhaps, but it is actually pretty easy to get your own.

If you have the camera plugged into the switch and set the camera IP to 10.te.am.11, the dashboard will save an image every second. Connect the ring light and walk around the target. The images will be saved into the user/documents/LabVIEW Data directory as a series of jpgs. You can also do this using the web browser or Vision Assistant, but you'll need to press a button each image and later save them.

Greg McKaskle

basicxman 11-01-2012 21:07

Re: Tracking Rectangles
 
Quote:

Originally Posted by Greg McKaskle (Post 1103018)
Perhaps, but it is actually pretty easy to get your own.

If you have the camera plugged into the switch and set the camera IP to 10.te.am.11, the dashboard will save an image every second. Connect the ring light and walk around the target. The images will be saved into the user/documents/LabVIEW Data directory as a series of jpgs. You can also do this using the web browser or Vision Assistant, but you'll need to press a button each image and later save them.

Greg McKaskle

Aye, I was just wondering if you had some already as I don't have a camera and cRio until tomorrow :)

shuhao 13-01-2012 14:22

Re: Tracking Rectangles
 
Is using OpenCV (JavaCV) more feasible than using NI vision if you're not using LabView then?

Our team is also considering putting a netbook on the robot to do the image processing (gotta figure out 12 -> 18V)... Is that really worth the trouble? I don't know how to get a netbook to communicate with the cRIO yet other than with the driver station...

Any ideas/suggestions?

Thanks

ProgrammerMatt 13-01-2012 14:31

Re: Tracking Rectangles
 
Quote:

Originally Posted by shuhao (Post 1104566)
Is using OpenCV (JavaCV) more feasible than using NI vision if you're not using LabView then?

Our team is also considering putting a netbook on the robot to do the image processing (gotta figure out 12 -> 18V)... Is that really worth the trouble? I don't know how to get a netbook to communicate with the cRIO yet other than with the driver station...

Any ideas/suggestions?

Thanks

You can have the netbook on the robot with the battery you dont need 12v to 18v.

and you can talk to the crio over a usb device such as an arduino or serial

shuhao 13-01-2012 15:00

Re: Tracking Rectangles
 
Is anyone else gonna be using OpenCV? (I, hopefully, will be able to use Python)

Also, what about the rule

Quote:

Robots must be controlled via one programmable National Instruments cRIO (part # cRIO-FRC or cRIO-FRCII), with image version FRC_2012_v43. Other controllers shall not be used.
Does a netbook count as another "controller"?

JewishDan18 13-01-2012 15:25

Re: Tracking Rectangles
 
Quote:

Originally Posted by shuhao (Post 1104566)
Is using OpenCV (JavaCV) more feasible than using NI vision if you're not using LabView then?

Our team is also considering putting a netbook on the robot to do the image processing (gotta figure out 12 -> 18V)... Is that really worth the trouble? I don't know how to get a netbook to communicate with the cRIO yet other than with the driver station...

Any ideas/suggestions?

Thanks

Personally, I don't think so, but that is for your team to judge. I have no facts to back this up, but I would bet money that the NI Vision is optimized pretty well for the CRIO and will give you better performance. Just the time required to convert the image to openCV format will be huge, since it is stored as a pointer to a block of memory containing a JPEG image (which you have to decompress to get individual pixel values from, so I'm not sure it would be feasible at all).

As far as the laptop goes, I would run the code on the driverstation, then send the results back rather than attach a laptop to the robot. Might be slightly slower, but a much smaller chance of getting destroyed :P

shuhao 13-01-2012 20:31

I've seen posts about how ni vision + their own tracking code lags other robot functions. Plus, openCV has way more resource, and I also get to use things like standard python, or other languages

Maybe raspberry pi? Hmmm

JewishDan18 13-01-2012 23:11

Re: Tracking Rectangles
 
It is working great for me, but YMMV. Proper threading should fix those problems. Using openCV in the CRIO would be very hard, as you would need to compile it for the CRIO to get that super fast C code. You should try both out and report back to us with some metrics, since I have nothing but my NI Vision code to speak for. Personally, I see no advantage to having the laptop on the robot, since the lag between the robot and the DS is negligible. Perhaps threshold on the CRIO, send the (much smaller) binary image to the laptop?

To address your earlier point about the legality of a laptop controller, all output to robot parts (motors, relays, etc) must come from the CRIO. You can send any signal you want to the crio, just not to anything else. Back in 2008 my team used current based speed controllers that were custom built circuit boards placed between the speed controller and the motor, and it was fun convincing the inspectors that they were legal :P

shuhao 13-01-2012 23:57

Well. I need to send data back to the crio if i want to image process else where. Im not sending driving instructions to the parts from the laptop. the crio handles those . Im just processing the image and sending a couple of things back, like heading and location etc.

JewishDan18 14-01-2012 00:27

Re: Tracking Rectangles
 
Quote:

Originally Posted by shuhao (Post 1105025)
Well. I need to send data back to the crio if i want to image process else where. Im not sending driving instructions to the parts from the laptop. the crio handles those . Im just processing the image and sending a couple of things back, like heading and location etc.

Right so it would be legal. But you should read the rules carefully; there is a max on the money spent on one part, on the motors (fan, hard drive, etc), power source (no batteries but the kit one, all power goes through distribution board). There is a reason very few teams go that route, and many teams are successful at image processing on the CRIO


All times are GMT -5. The time now is 10:29.

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