![]() |
Tower Tracker 1.0
Team 3019 graciously presents their vision tracking program for everybody to use and borrow! Now instead of dreaming about the perils of computer vision YOU can bring your team the joy of having a robot that is capable of tracking the target with ease! No more Grip crashes or weird deploys, can calculate fun things such as: distance to target, and angle to target! to be used to auto align and auto aim!
if you are going to modify the code, all i ask is give me and my team credit in a comment at the top of the code and comment your suggestions and or your praise! to install:
the code is just an example of what it can do, i can add network table stuff soon but i thought i would publish it first! github link want to see an example of what it can output? here you go! how it works: using an axis camera or a mjpeg streamer you can use a stream of a webcam to process images using an opencv program that runs on the driver station computer. This program can be modified to run on a coprocessor and directly input to the roborio for even better results because network tables can only go at 10hz vs the camera stream which is 30hz...this program can easily be ported over to c++ and python and would probably run better with those as c++ and python are way more supported then java with opencv. |
Re: Tower Tracker 1.0
Thank you!
We're looking at non-vision tracking options this year since the retro-tape is so high up. But we'll take a look at this code, too. |
Re: Tower Tracker 1.0
WOW! Awesome work! One question, Can this be deployed to run on the roborio ?
|
Re: Tower Tracker 1.0
Where do I install the Network Table 3.0 jar
|
Re: Tower Tracker 1.0
Quote:
Quote:
When you export the .jar file put it in a folder that looks similar to this where opencv_java310.dll could be opencv_java310.so for linux |
Re: Tower Tracker 1.0
Could this run on a C.H.IP computer?
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
Thank you for this code, I have ported it to c++. I am running it on a separate thread, but just with a static image for now. |
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Thank you so much for making your java vision tracking solution public. For our team vision tracking seemed extremely daunting but this made it a realistic task.
I am trying to run the jar but I get a couple of errors. I may have added the network table user library incorrectly. The steps I took are as follows: I made a new java project, added the user library for opencv following this tutorial: http://docs.opencv.org/2.4/doc/tutor...a_eclipse.html. Then I added the network table user library from this directory: C:\Users\Curtis Johnston\wpilib\java\current\lib. When I try to run the executable jar from command prompt I get the following errors. Code:
platform: /Windows/amd64/ |
Re: Tower Tracker 1.0
Quote:
Again, thank you for this code, it is very helpful. |
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
the specific file you want is the edu.wpi.first.wpilib.networktables.cpp:NetworkTabl es:3.0.0-SNAPSHOT there it has the instructions for downloading the newest .jar file for the network tables...I made the same mistake when making this |
Re: Tower Tracker 1.0
The roboRIO has two cores and a modern linux scheduler. All processes and threads will be assigned to a processor core based on priority and history of execution. The default robot code doesn't use the entire roboRIO to execute, and in fact can be made much lighter and efficient if that is what the team chooses to do.
It is quite easy to consume an entire core on any computer by writing one loop without a wait or delay of some sort. At that point, you can add more cores or fix the problem. There are intentionally many ways to approach the vision processing challenge, and the tradeoffs are as team-based as technical. I fully expect to see awesome processing based on the DB laptop, based on coprocessors, and based on just the roboRIO. None of these are, in my opinion, a bad approach. And of course there are teams who will solve the challenge with no camera at all. By the way, the DS shows you the CPU trace of the roboRIO in realtime. Just click on the second or third tab on the right side. This info is also logged and can be reviewed using the Log File Viewer after a practice or a match. If the robot feels sluggish, you can try to identify if it was because you maxed the CPU or something else. Greg McKaskle |
Re: Tower Tracker 1.0
Quote:
Its a bit messy, and the algorithm is a bit different, but you can change it easily. Also, im getting resource initialized error after a while. It might be an array error. |
Re: Tower Tracker 1.0
Also interested in running this on RoboRio and in C++. Anyone have any luck compiling a C++ WPIlib robot program with some opencv in it? If so, I'd love to hear how you did it.
|
Re: Tower Tracker 1.0
Thanks for sharing that! How did you get the opencv libraries onto the roborio? I've been having some trouble with that
|
Re: Tower Tracker 1.0
wow! Amazing!
I just wish that we had something like that in labview :/ |
Re: Tower Tracker 1.0
Quote:
Ideally, I'd love to see this processed on board with a raspberry pi or arduino board, but that's version 2.0 stuff. |
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Nicely done.
So how would you use this to get the values of the contours? Lets say I want my robot to "auto" shoot when the contours are a specific dimension. Anyway I can do that with this ? Thanks. |
Re: Tower Tracker 1.0
Quote:
essentially you need to find the amount that your shooter can be off (tolerance) while still "scoring", for instance it can make it anywhere from 6-8 feet from the goal. Then you need to make sure your robot keeps driving until it is somewhere between that tolerance and then it can start its fire sequence. I would recommend looking into a pid drive system for that, its a closed loop drive that would work nicely with this. |
Re: Tower Tracker 1.0
Quote:
Quote:
|
Re: Tower Tracker 1.0
Quote:
Greg McKaskle |
Re: Tower Tracker 1.0
When trying to run the program on the Jetson TK1, I get the error
Code:
java.lang.UnsatisfiedLinkError: no libopencv_java2410 in java.library.pathThank you! -Chris |
Re: Tower Tracker 1.0
In case anyone is still daring to try to do vision on the Rio, and wants to put it right in their normal C++ project, I was able to (finally) get opencv to build for ARM and integrate into a WPILib project. Been unable to test on a Rio so far, but at least it builds. Here's an example project with the special opencv build and a file (BuildOpenCV.txt) explaining how to set it up. Was a big PIA for me, so thought i'd leave notes on the steps I went through. You can just throw in your own source files into the project, but make sure to delete/comment out the line #define REAL in WPILib.h, as it creates some conflict of OPENCV. Okay it's 3 a.m I should go to sleep now.
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Nevermind, I have no idea what I'm doing.
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
FYI, anyone looking for a precompiled version of opencv 3.1 for the roboRIO, the robotpy project has had one available since before build season. Works with C++, Java, and Python 2/3 -- very easy to install the shared libraries on the roboRIO through our opkg repo.
https://github.com/robotpy/roborio-opencv |
Re: Tower Tracker 1.0
you can do this on $35 Raspberry pi and save critical RoboRio resources
see this Look here for tracking shronghold goalpost http://www.mindsensors.com/blog/how-...our-frc-robot- |
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
Now, would you be willing to help me setup my build environment for cross compiling an OpenCV program in C++ that will use the shared libs on the RoboRio (preferably in Eclipse)? EDIT: Information on setting up build environment is avaible on the latest release on gituhub. Wow, that was easy! |
Re: Tower Tracker 1.0
Can this work with usb cameras?
|
Re: Tower Tracker 1.0
*My java opencv is a little rusty*
Here is how you use a use camera with the opencv libraries and store the image in the data type Mat. VideoCapture camera = new VideoCapture(0); Mat frame = new Mat(); camera.read(frame); instead of videoCapture = new VideoCapture(); //replaces the ##.## with your team number videoCapture.open("http://10.##.##.11/mjpg/video.mjpg"); |
Re: Tower Tracker 1.0
Yes, if you are going to use a usb webcam I would recommend mjpeg streamer and running it off of the driverstation.
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
My team is trying to use your code to test our vision but every time we run the executable JAR file we get two errors-
"Error opening file </build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:578>" and when we try to use the network table, we get the error "NT: Error: could not resolve roborio-3929.local address <TCPConnecotr.cpp:93>". We've installed opencv 3.1 and we are able to stream camera output to the dashboard. We are using the microsoft livecam 3000. Any help would be appreciated. Thanks! |
Re: Tower Tracker 1.0
1 Attachment(s)
My robotics team is also getting the same error that everyone else is. When we try and run it in the command prompt is gives us the error that it is having a hard time with having Open CV in the library. It can't find it but it is in there. Any ideas on how to fix it? We followed the directions as it said and nothing works. We also added the DLL file in Open CV folder to system 32. I included a screenshot of the error we were getting. Please help.
|
Re: Tower Tracker 1.0
Quote:
Quote:
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
I modified the code to output distance values to the network table. When I add code to put the distance value on the dashboard, no values show up. Also, when I use the OutlineViewer to check any networktable values (with the localhost as "roboRIO-3929-FRC.local"), nothing shows up except the Root folder. Did you get the network table to work?
|
Re: Tower Tracker 1.0
Quote:
Code:
while(!NetworkTable.isConnected()){} |
Re: Tower Tracker 1.0
Quote:
(Note: Its been 28 or so years since I had to do more complicated math so go easy on me). It looked like in the code you had a known angle of the camera (I'm assuming vertical angle.) and you are plugging that in. I get how this works more or less for figuring out distance/vertical angle. Where we are struggling a bit is in figuring out when we are "off center" - given what you can get out of a contour I'm not sure we would know that we need to move a bit to the right or left in order for a shot to work. Did you wind up solving that? If the contour had given us the boundaries of the rectangle's length or coordinates then I think we could evaluate relative sizes to know to move left or right but I'm not sure even about that. Any feedback is appreciated! |
Re: Tower Tracker 1.0
Would this code work with a Microsoft Lifecam?
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Has anyone gotten a python version of this code to work?
In python many of the methods that this code requires do not exist and this is a problem for many teams that plan on using Python for their vision processing. We have trying to port this code for use as sample code for days but as you can see many of the functions do not exist which causes problems. Here is our code.. so far http://pastebin.com/ecdDFDQp the rectangle class is the main problem we are being faced with. There seems to be no equivalent for those using Python. If anyone has found a solution to this issue. Then please let us know! Thanks! |
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
We got it all compiled into a jar and running, but it never seems to open the connection to the camera. It's at the right IP, if we put the address in the code in our browser the mjpg stream comes up, but it just sits at opening forever in the cmd prompt.
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
Any idea? |
Re: Tower Tracker 1.0
Do you know if you can find the distance with this anyone
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Thanks for the code, really helped! If anyone is having trouble with the thresh holds you can take the HSV image to http://html-color-codes.info/colors-from-image/ to pull the hex colors of the target. Once you have 3-5 hex colors simply convert them to bgr and find the range from high to low (add/subtract 10% on either end to make it work better).
|
Re: Tower Tracker 1.0
Quote:
Honestly, my team just used grip to find the values, its easy to use and with the sliders. |
Re: Tower Tracker 1.0
First, thanks for posting this. We have been struggling with vision code for some time now. However, I am having difficulty figuring out how to install the networktables. I can't figure out how to find the correct files and download them by following the instructions on this page.
Thanks again for all these resources! |
Re: Tower Tracker 1.0
Just wanted to post and say we ran a modified version of TowerTracker on a Jetson TK1 at the Greater Kansas City regional this weekend with great success. Thank you Fauge and team 3019 for sharing your work. :)
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Tower tracker is now award winning! Shout out to team 1806 Swat! Congrats on going 15-0 at this week's regional! Proof the program can change robots. If anybody needs help with implementing it I am more then happy to help. Pm me with questions.
|
Re: Tower Tracker 1.0
Hello. We are having trouble running it on a raspberry Pi. We I try to run the exported jar I get an no opencv_java310 in Java.library.path. Would love to be able to use it for this regions just having some trouble getting it to work. Opencv 310 is installed and compiled on the Pi.
|
Re: Tower Tracker 1.0
Hey!
when you are building the java file, make sure to include the opencv jar file in your class path. An easy way to do this is to using the -cp command while building. Doing this will work: java -cp /home/pi/opencv/build/bin/opencv-310.jar TowerTracker.jar This configures the class path to include the jar for OpenCV which is the error that you are facing. /home/pi/opencv/build/bin is the default location for the jar. If you need any more help with this. Feel free to PM me! I went through this same process last week :) |
Re: Tower Tracker 1.0
Hey guys!
How do you calibrate the camera, exactly... I have opened up GRIP and got the RGB values of a setup in which the goal is clear and then took those values and edited the Lower and Upper bounds respectively but have been getting 0 contours.. Thanks! |
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
I am using an untouched version of TowerTracker and I found RGB values on GRIP and I put them as the Upper and Lower Bounds in BGR order and I still am detecting nothing. Any suggestions? Thanks!
|
Re: Tower Tracker 1.0
Can you use imshow to display a window of what your original, resize, and threshold Mat's look like? That might help.
|
Re: Tower Tracker 1.0
I am not sure how to do so. I am running the Java code provided. I remember your team discussing this on another thread. How exactly do you guys calibrate because that seems to be the problem.
Thanks! |
Re: Tower Tracker 1.0
To calibrate the camera, what we did was save the first image it grabbed and then downloaded it onto our pc. Then we brought it into GRIP and found the right RGB values. Then we just plugged it into lower and upper bounds arguments. It worked for us. We did have an issue where we had a really bright image right when the camera started. My best guess is because the camera lens is still adjusting its white balance or something like that. But when just ran the code again after the camera was on for a second. This wasn't a problem in competition because your robot is on a while before the match starts.
|
Re: Tower Tracker 1.0
1 Attachment(s)
Elaborate on the finding the perfect RGB values. Would you find these to be good?
|
Re: Tower Tracker 1.0
I would actually recommend doing your calibration in the HSB/HSV color space, as it separates color(H) from brightness(B/V) which means you can get a more robust calibration that will working in many different lighting environments (as the color your LEDs output shouldn't change) provided you turn your camera's exposure down.
|
Re: Tower Tracker 1.0
and how to modify the code to use HSV instead of RGB?
|
Re: Tower Tracker 1.0
Quote:
Also, those values seem fine to me. I think i see the issue. Tower Tracker checks if the goal bounding rectangle is wider than it is tall. So when viewing from sharp angles like that is not going to give you a selected contour. Do you have a test image where the goal is straight on? If not, you can just get rid of this segment of code: Code:
float aspect = (float)rec.width/(float)rec.height; |
Re: Tower Tracker 1.0
Oh! Thanks so much! We were hoping to have this running by this Saturday for our competition! :)
|
Re: Tower Tracker 1.0
So it works? If so, good luck at competition. Any questions, PM me or post here.
|
Re: Tower Tracker 1.0
Sorry for double post but just making sure you see this...
I would also check for solidity of the target. This makes sure you don't get stray objects even if it passes all other checks. Here is c++ code, very similar to java. Code:
float area = contourArea(contours[i]); |
Re: Tower Tracker 1.0
The aspect ratio part of the code helps filter out things that the hsv filter cannot. We know the target is always wider then it is tall therefor it's aspect ratio will always be greater then 1 and if it's not don't detect it as a possible target. There are other things you can do to help but my team has found its good enough. You always know it's going to be atleast a certain pixel range because you can only shoot from a certain part.
|
Re: Tower Tracker 1.0
Quote:
I also added checks for solidity in my c++ version here if you want to check it out. Just like in grip. |
Re: Tower Tracker 1.0
Yes! It turned out that the bounds are in HSV and not RGB and that solved some problems. I am hoping to get some good pics during field calibration today for the our event and calibrate correctly! Thanks guys for all the help!
|
Re: Tower Tracker 1.0
Quote:
|
Re: Tower Tracker 1.0
Quote:
Code:
Exception in thread "main" java.lang.NullPointerException at org.usfirst.frc.team5407.robot.TowerTracker.main(TowerTracker.java:107) |
Re: Tower Tracker 1.0
Yes, I messed up the github code but luckly one of my team members has the code on his github. https://github.com/Aventek/TowerTracker3019Modified
Hopefully this helps, pm me if you have any questions! |
Re: Tower Tracker 1.0
This may be a dumb question. But could someone please explain to me the "fun" math i am not really sure how its doing what it is doing.....
|
Re: Tower Tracker 1.0
Quote:
Code:
y = rec.br().y + rec.height / 2;Code:
double half_image_height = matOriginal.height() / 2;With that change, this operation makes a bit more sense. The point is to calculate the offset in normalized coordinates from the middle of the target to the horizon. The horizon is assumed to be at (matOriginal.height()/2). First, it subtracts the y-coordinate of the middle of the target from half of the image size in pixels. This results in the pixel offset between the horizon line on the image to the target y-coordinate. Then, the entire thing is normalized by dividing it by half the pixel image height. ![]() Code:
distance = (TOP_TARGET_HEIGHT - TOP_CAMERA_HEIGHT) / Math.tan((y * VERTICAL_FOV / 2.0 + CAMERA_ANGLE) * Math.PI / 180);There are two parts. First, the angle from the horizon to the target is approximated using the small angle approximation. Code:
(y * VERTICAL_FOV / 2.0 + CAMERA_ANGLE) * Math.PI / 180Code:
angle = arcsin( pixel_y * sin(VERTICAL_FOV/2.0) / half_image_height )Now the camera may be tilted relative to the field, meaning that its local "horizon" isn't the same, so the offset CAMERA_ANGLE is added, for the angle that the camera is tilted relative to the actual horizon. Now the final part is to calculate the distance using the known height of the target and this calculated angle to the horizon. ![]() h is the distance from the camera's height to the target's height (TOP_TARGET_HEIGHT - TOP_CAMERA_HEIGHT), so tan(alpha) = h/d => d = h/tan(alpha) I hope this explains it. |
Re: Tower Tracker 1.0
I am very likely working on a faulty understanding of FOV but wouldn't this be much simpler?
Code:
double AngleToHalfScreen = Vertical_FOV/2;Thank you so much for taking the time to explain this. |
| All times are GMT -5. The time now is 22:01. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi