Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Open CV help (http://www.chiefdelphi.com/forums/showthread.php?t=154625)

elijah1111 02-02-2017 16:51

Open CV help
 
Hey anybody got any ideas on Open CV? We were planning on using it for auto gears.
Code:

static void VisionThread(){
//blah blah set up cameras

while(true){
inRange(mat,cv::Scalar(0,100,0),cv::Scalar(100,255,100),mat)//find green light
cv::findContours(mat,contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_TC89_KCOS);//find reflect tape
                        cv::drawContours(mat,contours,-1,cv::Scalar(255,255,255),1,8);//draw them
cameraserver.putframe(mat);//put the modifed image matrix
centerpoints.read()//I need to find the centerpoints here how would I do that?
}
}

void RobotInit(){
std::thread camthread(VisionThread);//makes a new thread
camthread.detach();//snaps the thread off to do its own thing
}

void AutonomousPeriodic(){
 camera.read()//Here is where I need help how do I get the two threads to talk
}

Anybody got any suggestions? I was thinking if you could calculate the distance between the two center points and you know the actual distance you can find out how far you are from the peg for the gear.

Thanks,
Elijah
4601

P.S. actual code is here https://github.com/CircuitBirds-FRC4601/CB5

billbo911 02-02-2017 17:04

Re: Open CV help
 
My biggest concern with this approach is that the gear itself will be covering those two pieces of retro tape most of the time when aligned. Encoders might be a better approach.

elijah1111 02-02-2017 17:16

Re: Open CV help
 
I agree, if you get to start in front of the peg facing the wall, but what about the other ones? You would need to preset it in a certain location which seems harder this year.

elijah1111 02-02-2017 17:23

Re: Open CV help
 
Quote:

Originally Posted by billbo911 (Post 1639619)
My biggest concern with this approach is that the gear itself will be covering those two pieces of retro tape most of the time when aligned. Encoders might be a better approach.

what do you mean by covering them? I was thinking of finding the distance between the tape before you put the gear on then reading encoder counts for that distance.

billbo911 02-02-2017 17:28

Re: Open CV help
 
Quote:

Originally Posted by elijah1111 (Post 1639626)
what do you mean by covering them? I was thinking of finding the distance between the tape before you put the gear on then reading encoder counts for that distance.

Now that just might work. You would just need to have some way to tell the RC when to lock in the distance.

elijah1111 02-02-2017 17:45

Re: Open CV help
 
Quote:

Originally Posted by billbo911 (Post 1639628)
Now that just might work. You would just need to have some way to tell the RC when to lock in the distance.

Yah, that is my problem I'm pretty sure I open cv has the capability for doing that but how do I pass it to the auto code, because its a static void for the multi threading.

Maxcr1 02-02-2017 18:38

Re: Open CV help
 
The secret to using vision for Steamworks is having an angle of attack of the camera to avoid the gear getting in the way of seeing the tape. The vision is possible and the calculations do exist, and aren't too bad if you follow 254's presentation.

Vision Presentation

Multithreading is often unrealistic because all of the tasks have to be run in a linear pattern, and while running multiple versions can be effective, it causes issues with multiple threads fighting over the same frame. You can use a lock, but that requires Python and that can be another issue

elijah1111 02-02-2017 18:52

Re: Open CV help
 
Quote:

Originally Posted by Maxcr1 (Post 1639647)
The secret to using vision for Steamworks is having an angle of attack of the camera to avoid the gear getting in the way of seeing the tape. The vision is possible and the calculations do exist, and aren't too bad if you follow 254's presentation.

Vision Presentation

Multithreading is often unrealistic because all of the tasks have to be run in a linear pattern, and while running multiple versions can be effective, it causes issues with multiple threads fighting over the same frame. You can use a lock, but that requires Python and that can be another issue

By frame do you mean the image? The multithread would be linear, there is only one thread for camera. I just need the auto to tell that thread to find the distance between the center points then relay it back to convert to encoder values. I am multithreading because the open cv capture and operations would bog down the robot. Of course I could always just take a still image of the tape but i figured it would be better to take a video to average out the distances.


All times are GMT -5. The time now is 07:05.

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