we are attempting to use HSV color thresholding to track objects on the ground using a wireless camera mounted on our quadcopter. Wireless commands are sent through a Futaba R/C controller connected to our Linux computer using a USB interface. Qt is being used to run and compile our c++ code.
The goal is to identify that an object (of a specified color) is within the field of view and then commands are sent to the quadcopter which will instruct the craft to fly towards the object. Currently the geometric center of the object is found and its pixel coordinates are used to decide which way the craft should fly. In the code listed below, commands are sent even without the presence of an object on the screen.
Why are commands being sent to the craft before an object is present in the field of view? Why does the craft continue to respond after the object has reached the center of the screen? (240 pixels)?
My guess is the loops are improperly structured but I have very little coding experience and would appreciate your input! Thanks!
int main(int argc, char* argv[])
{
//Matrix to store camera frames
Mat cameraFeed;
Mat threshold,thresholdRed,thresholdBlue,thresholdGreen;
Mat HSV;
VideoCapture capture;
capture.open(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH,FRAME_WIDTH);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,FRAME_HEIGHT);
//Create infinite loop
bool loop = true;
while(loop)
{
capture >> cameraFeed;
capture.read(cameraFeed);
//Convert to HSV
cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
//ADD GAUSIAN BLUR
GaussianBlur(HSV,HSV,Size(5,5),0,0);
Object groundRobotRed("groundRobotRed");
//Values taken from trackbars
groundRobotRed.setHSVmin(Scalar(18, 44, 103));
groundRobotRed.setHSVmax(Scalar(36,142,249));
inRange(HSV,groundRobotRed.getHSVmin(),groundRobotRed.getHSVmax(),thresholdRed);
morphOps(thresholdRed);
trackFilteredObject(groundRobotRed,thresholdRed,HSV,cameraFeed);
//Quadcopter Systems Check
if (flying == 0)
{
std::cout<<"hello:"<<std::endl;
test_control.conn();
test=test_control.isConnected();
cout<<"test:"<<test<<endl;
if (test)
testing();
else
loop = false;
}
//If object is located on the top of the screen
if(groundRobotRed.getYPos()<<240)
{
//Pitch forward command
test_control.transmit(570, 565, 500, 500, 0, 0, 0, 0, 0);
std:cout<<"Pitch Complete"<<std::endl;
}
else
{
//Hover command
test_control.transmit(570,565,500,500,0,0,0,0,0);
}
capture.release();
HSV.release();
thresholdRed.release();
capture.open(0);
imshow(windowName,cameraFeed);
waitKey(10);
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire