Go to Post 'We're back to square one! and while we're at it, let's redesign square one.' - Bethie42 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-01-2017, 21:00
skidad68 skidad68 is offline
Registered User
FRC #2506
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2013
Location: United States
Posts: 13
skidad68 is an unknown quantity at this point
Vision problem - robot view not matching Grip view

Our team is having some difficulty with the Grip generated code. We are getting a different result when we run the pipeline on the roboRIO vs. the PC.

I am attaching a Word document with some screen captures. One shows the result of HSV threshold detection on the robot, and the other shows the same result on the PC. As you can see they are wildly different.

Both are using the same Microsoft USB camera mounted on the robot, illuminated with a green LED ring.

Any ideas as to what is going wrong?

(Edited to add: we are using Java if that makes any difference)
Attached Files
File Type: docx frc screen cap.docx (1.38 MB, 71 views)

Last edited by skidad68 : 26-01-2017 at 21:14. Reason: added clarification
Reply With Quote
  #2   Spotlight this post!  
Unread 26-01-2017, 21:08
Jayd009's Avatar
Jayd009 Jayd009 is offline
Registered User
AKA: Jonathan
FRC #4468 (Fernbank LINKS)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Atlanta, Georgia
Posts: 32
Jayd009 is on a distinguished road
Re: Vision problem - robot view not matching Grip view

Are you using the publish video block in your GRIP pipeline?
__________________
2016: District Event Winner @ Columbus District Qualifier (PCH)
2016: Engineering Inspiration Award @ Peachtree District State Championship
2016: Tesla Subdivision Playoffs Appearance @ FIRST Championship


Reply With Quote
  #3   Spotlight this post!  
Unread 26-01-2017, 21:14
skidad68 skidad68 is offline
Registered User
FRC #2506
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2013
Location: United States
Posts: 13
skidad68 is an unknown quantity at this point
Re: Vision problem - robot view not matching Grip view

We've hacked the generated hsvThreshold() method to add a call to CvSource.putFrame().
Reply With Quote
  #4   Spotlight this post!  
Unread 26-01-2017, 22:15
Thad House Thad House is online now
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,107
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: Vision problem - robot view not matching Grip view

The reason for this is that OpenCV actually modifies the Mat passed into it when running findContours. Since the Mat from the HSV Threshold is passed into findContours directly, it modifies the Mat that is being sent to the dashboard.

The solution to this is to create a new Mat in the class (call it hsvSend or something like that). Then at the end of the HSVThreshold function, call hsvout.copyTo(hsvSend);. Then putSource the hsvSend mat instead of the hsvout mat

hsvout might not be the right name, I don't remember. But it's just the one that is the output from the inRange function.

As another hint, you are HIGHLY overexposing your image. Either lower the voltage to your light source, or lower the exposure on the camera. It will make tracking much easier and more reliable.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.
Reply With Quote
  #5   Spotlight this post!  
Unread 26-01-2017, 22:40
skidad68 skidad68 is offline
Registered User
FRC #2506
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2013
Location: United States
Posts: 13
skidad68 is an unknown quantity at this point
Re: Vision problem - robot view not matching Grip view

Thanks for the tip.

Follow-up question: Is there a way to set the exposure in GRIP? Otherwise the HSV calibration we do there isn't going to be close.
Reply With Quote
  #6   Spotlight this post!  
Unread 31-01-2017, 21:22
skidad68 skidad68 is offline
Registered User
FRC #2506
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2013
Location: United States
Posts: 13
skidad68 is an unknown quantity at this point
Re: Vision problem - robot view not matching Grip view

So I've been monkeying around with this for some time now, and I think the real problem is that the HSV thresholds generated by GRIP don't produce the same results on the roboRIO. (Note that the camera I used to tune GRIP is the same one used by the roboRIO). Plus, the lack of brightness control in GRIP makes it pretty much useless for tuning as the brightness is a critical setting to improve noise rejection.

To figure this out, I had to modify the generated pipeline to make all of the tuning parameters variable, and then use the SmartDashboard to tune the parameters and monitor the result in real time.

Now I can at least tune the vision accurately, but we're having some problems with the camera producing consistent readings. But that's probably a topic for another thread...
Reply With Quote
  #7   Spotlight this post!  
Unread 01-02-2017, 09:32
wlogeais wlogeais is offline
Registered User
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2016
Rookie Year: 2011
Location: Minnesota
Posts: 18
wlogeais is an unknown quantity at this point
Re: Vision problem - robot view not matching Grip view

Quote:
Originally Posted by skidad68 View Post
So I've been monkeying around with this for some time now, and I think the real problem is that the HSV thresholds generated by GRIP don't produce the same results on the roboRIO. (Note that the camera I used to tune GRIP is the same one used by the roboRIO). Plus, the lack of brightness control in GRIP makes it pretty much useless for tuning as the brightness is a critical setting to improve noise rejection.
Yes, this is going to be true whenever the Robot calls the (CameraServer's) setResolution(...) and/or setContrast(...) methods. Good that you figured out how to adjust your HSV parameters into modified generated-code. The other (easier) approach to this should be to have the modified camera-server running on the RIO, and then have GRIP connect to this stream via 'add-ip-camera' in GRIP , eg with http://roborio-TEAM-frc:1181.
Reply With Quote
  #8   Spotlight this post!  
Unread 02-02-2017, 21:46
skidad68 skidad68 is offline
Registered User
FRC #2506
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2013
Location: United States
Posts: 13
skidad68 is an unknown quantity at this point
Re: Vision problem - robot view not matching Grip view

So regarding the camera consistency issues:

It is critical to override all of the camera's automatic exposure control features. (We are using the Microsoft Lifecam HD3000) We found that at a minimum we had to call:
setWhiteBalanceManual()
setExposureManual()
setBrightness()

There also seem to be scenarios where the above calls occasionally fail. I haven't been able to consistently reproduce this, so I can't say exactly what causes this. We were able to work around it by making the calls multiple times.

(One theory I haven't been able to test is that there is a race condition at camera start-up and you need to wait awhile after creating the camera object before calling the setters above)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:14.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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