Esempio n. 1
0
imageCapture::imageCapture(Mat image, int& counter, int amountOfColors, int AmountOfProjectedPointsPerColor, int totalProjectedColumns, vector<vector<Point>>& twoDPointSpace) {
	colorObject redLower("redLower"), redUpper("redUpper"), green("green"), blue("blue"), white("white");

	// get blue points
	cvtColor(image, HSV, COLOR_BGR2HSV);
	inRange(HSV, blue.getHSVmin(), blue.getHSVmax(), threshold);
	morphOps(threshold);
	trackFilteredObject(blue, threshold, image, counter, twoDPointSpace);

	// get red points
	cvtColor(image, HSV, COLOR_BGR2HSV);
	inRange(HSV, redLower.getHSVmin(), redLower.getHSVmax(), lowerRedImage);
	inRange(HSV, redUpper.getHSVmin(), redUpper.getHSVmax(), upperRedImage);
	addWeighted(lowerRedImage, 1.0, upperRedImage, 1.0, 0.0, threshold);
	morphOps(threshold);
	trackFilteredObject(redUpper, threshold, image, counter, twoDPointSpace);

	//get green points
	cvtColor(image, HSV, COLOR_BGR2HSV);
	inRange(HSV, green.getHSVmin(), green.getHSVmax(), threshold);
	morphOps(threshold);
	trackFilteredObject(green, threshold, image, counter, twoDPointSpace);

	//get white points
	cvtColor(image, HSV, COLOR_BGR2HSV);
	inRange(HSV, white.getHSVmin(), white.getHSVmax(), threshold);
	morphOps(threshold);
	trackFilteredObject(white, threshold, image, counter, twoDPointSpace);

	counter++;
}
int main(int argc, char* argv[])
{
    //if we would like to calibrate our filter values, set to true.
    bool calibrationMode = true;

    //Matrix to store each frame of the webcam feed
    Mat cameraFeed;
    Mat threshold;
    Mat HSV;

    if(calibrationMode)
    {
        //create slider bars for HSV filtering
        createTrackbars();
    }

    //while(1)
    {
        src = imread("/home/yf/Pictures/tack2.png", 1);
        cameraFeed = src;

        if( !src.data )
        { return -1; }

        //convert frame from BGR to HSV colorspace
        cvtColor(src,HSV,CV_BGR2HSV);

        //need to find the appropriate color range values
        // calibrationMode must be false

        //if in calibration mode, we track objects based on the HSV slider values.
        cvtColor(cameraFeed,HSV,CV_BGR2HSV);
        inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold);
        morphOps(threshold);
        imshow(windowName2,threshold);

        //the folowing for canny edge detec
        /// Create a matrix of the same type and size as src (for dst)
        dst.create( src.size(), src.type() );
        /// Convert the image to grayscale
        cvtColor( src, src_gray, CV_BGR2GRAY );
        /// Create a window
        namedWindow( window_name, CV_WINDOW_AUTOSIZE );
        /// Create a Trackbar for user to enter threshold
        //createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold);
        /// Show the image
        trackFilteredObject(threshold,HSV,cameraFeed);

        //show frames
        //imshow(windowName2,threshold);

        imshow(windowName,cameraFeed);
        //imshow(windowName1,HSV);

        //delay 30ms so that screen can refresh.
        //image will not appear without this waitKey() command
        waitKey();
    }
    return 0;
}
Esempio n. 3
0
void ballDetect :: initDetect(char *videoInput){

    VideoCapture capture;
    Mat src, src_HSV, processed;
    int x=0; int y=0; 

    Mat currentFrame, back, fore;   
    BackgroundSubtractorMOG2 bg;

    std::vector<std::vector<cv::Point> > contours;

    capture.open(videoInput);
    capture.set(CV_CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);

    // int xyz=1;

    while(1){

        // cout<<xyz++<<endl;
        capture.read(src);
        cvtColor(src, src_HSV, COLOR_BGR2HSV);

        bg.operator ()(src, fore);
        bg.getBackgroundImage(back);
        erode(fore, fore, Mat());
        dilate(fore, fore, Mat());
        findContours(fore, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
        // drawContours(src,  contours,  -1,  Scalar(0,  0,  255),  2);
        contourCount=contours.size();

        if(white_collide.x != -1 && white_collide.y!=-1){
            circle(src, white_collide, 2, Scalar(0, 0, 0), 2);
            circle(src, white_initial, 2, Scalar(0, 0, 0), 2);
            line(src, white_initial, white_collide, Scalar(255, 255, 255), 1, CV_AA);
        }

        inRange(src_HSV, *minval, *maxval, processed);
        morphOps(processed);
        trackFilteredObject(x, y, processed, src);

        for(int i=0;i<(int)white_position.size()-1;++i){
            line(src, white_position[i], white_position[i+1], Scalar(255, 255, 255), 1, CV_AA); 
        }
        while(white_collide.x == -1 && white_collide.y==-1){
            setMouseCallback("source", onMouseClick, &src);
            putText(src, "Specify Point", Point(750, 40), 1, 1, Scalar(255, 0, 0), 2);
            imshow("source", src);
            waitKey(5);
        }

        imshow("source", src);
        waitKey(5);
    }
}
void visual_servoing::processImage(const sensor_msgs::ImageConstPtr& msg)
{
	// Convert the ROS image to an OpenCV Image
	cv_bridge::CvImagePtr cv_ptr;

	// try
	// {
		cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
	// }
	// catch(cv_bridge::Exception& e)
	// {
	// 	ROS_ERROR("cv_bridge exception: %s", e.what());
	// 	return;
	// }

	Mat camerafeed = cv_ptr->image;
	Mat threshold;
	Mat HSV;

	// visual_servoing the threshed image
	createTrackbars();
	cvtColor(cv_ptr->image,HSV,COLOR_BGR2HSV);

	cvtColor(cv_ptr->image,HSV,COLOR_BGR2HSV);
	inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX), threshold);
	morphOps(threshold);
	imshow(windowName2,threshold);
	trackRobot(this->robot, threshold,HSV,cv_ptr->image);
	cv::setMouseCallback("Original Image", mouseEventCallback, &(this->clickedPoint));

	//Robot's position over time
	int robotX = this->robot.getXPos();
	int robotY = this->robot.getYPos();
	int clickedX = (int)this->clickedPoint.x;
	int clickedY = (int)this->clickedPoint.y;

	// Draw target point
	if(clickedX != -1 && clickedY != -1)
	{
		cv::circle(cv_ptr->image, cv::Point(clickedX, clickedY), 5, cv::Scalar(255, 0, 0));
		cv::putText(cv_ptr->image, intToString(clickedX)+ " , " 
				+ intToString(clickedY), cv::Point(clickedX, clickedY + 20), 1, 1,Scalar(255, 0, 0));
	}

	// Calculate deltas

	int delta_x = robotX - clickedX;
	int delta_y = robotY - clickedY;


	imshow(windowName,cv_ptr->image);
	waitKey(3);
}
Esempio n. 5
0
// this folk is responsible for modifying the video preview (each img frame)
// by colour detecting and drawing a green frame
void do_frame ( Mat& cameraFeed, cv::Scalar hsv_min, cv::Scalar hsv_max ) {

  Mat HSV;
  Mat threshold;

  // Object white("white");
  //white
  // opencv cvtColor: http://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html
  // test and know
  cvtColor(cameraFeed, HSV, COLOR_BGR2HSV); /*not clear if image comes rgb(a) or bgr from java - bgr it is, yep!*/
  // cvtColor(cameraFeed,HSV,CV_RGB2HSV); /*not clear if image comes rgb(a) or bgr from java*/

  // inRange(HSV,white.getHSVmin(),white.getHSVmax(),threshold);
  inRange(HSV, hsv_min, hsv_max, threshold);
  morphOps(threshold);
  trackFilteredObject ( threshold );
}
// Created by Marzouq Abedur Rahman 16/11/2015
// Priority level 1, carry out experiments immediately after Mark 1 arrive.
// This program will only work in direct input, so additional tweaks must be made for the response to be in 'MAVlink'
// format.
// Not a big deal, just use os commands as the raspberry pi will do the image processing.
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, insert the mavlink command here
         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;
}
Esempio n. 7
0
int main(int argc, char* argv[])
{
	cuerpo humano;
	bool grabarmeneada = false;
	bool calibrationMode = false;
	Mat cameraFeed;
	Mat threshold;
	Mat HSV;
	cv::Size frameSize(FRAME_WIDTH, FRAME_HEIGHT);
	Mat figura= Mat::zeros(frameSize, CV_8UC1);
    vector<Mat> spl;

	if(calibrationMode){
		createTrackbars();
	}
	VideoCapture captura;
	captura.open(1);
    //
    cv::VideoWriter grabar;

    //figura = Mat::zeros(frameSize, CV_8UC1);
    if(grabarmeneada){
        string filename = "meneate.avi";
        //fcc
        int fcc = CV_FOURCC('D','I','V','3');
        int fps = 10;

        grabar = VideoWriter(filename, fcc, fps, frameSize);
        if(!grabar.isOpened()){
            cout<<"ERROR al grabar archivo"<<endl;
            getchar();
            return -1;
        }

    }
	captura.set(CV_CAP_PROP_FRAME_WIDTH,FRAME_WIDTH);
	captura.set(CV_CAP_PROP_FRAME_HEIGHT,FRAME_HEIGHT);

	while(1){

		captura.read(cameraFeed);

		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);

		if(calibrationMode==true){
            cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
            inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold);
            morphOps(threshold);
            imshow(windowName2,threshold);
            trackFilteredObject(threshold,HSV,cameraFeed,figura, humano);
		}else{
		    nodo marca;
		    marca.setHSVmin(Scalar(24,2,240));
		    marca.setHSVmax(Scalar(85,115,256));
            cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
            inRange(HSV,marca.getHSVmin(),marca.getHSVmax(),threshold);
            morphOps(threshold);
            trackFilteredObject(threshold,HSV,cameraFeed,figura, humano);
            if(grabarmeneada){
                split(cameraFeed, spl);
                for (int i =0; i < 3; ++i)
                    spl[i] = figura;
                merge(spl, figura);
                grabar.write(figura);
            }
		}
		imshow(windowName2,threshold);
		imshow(windowName,cameraFeed);
		grabar.write(figura);
		imshow(meneate,figura);
		//imshow(windowName1,HSV);
        switch(waitKey(1)){
            case 27://ESC
                return 0;
        }
		waitKey(10);
	}
	return 0;
}
int main(int argc, char* argv[])
{
	//if we would like to calibrate our filter values, set to true.
	bool calibrationMode = true;
	
	//Matrix to store each frame of the webcam feed
	Mat cameraFeed;
	Mat threshold;
	Mat HSV;

	if(calibrationMode){
		//create slider bars for HSV filtering
		createTrackbars();
	}
	//video capture object to acquire webcam feed
	VideoCapture capture;
	//open capture object at location zero (default location for webcam)
	capture.open(1);
	//set height and width of capture frame
	capture.set(CV_CAP_PROP_FRAME_WIDTH,FRAME_WIDTH);
	capture.set(CV_CAP_PROP_FRAME_HEIGHT,FRAME_HEIGHT);
	//start an infinite loop where webcam feed is copied to cameraFeed matrix
	//all of our operations will be performed within this loop
	while(1){
		//store image to matrix
		capture.read(cameraFeed);
		//convert frame from BGR to HSV colorspace
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
		//cvtColor(cameraFeed,HSV,COLOR_BGR2YCrCb);

		if(calibrationMode==true){
		//if in calibration mode, we track objects based on the HSV slider values.
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
		//cvtColor(cameraFeed,HSV,COLOR_BGR2YCrCb);
		inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold);
		morphOps(threshold);
		imshow(windowName2,threshold);
		trackFilteredObject(threshold,HSV,cameraFeed);
		}else{

			Sample BlueRock("BlueRock"), RedPuck("RedPuck"), OrangePipe("OrangePipe"), PinkBall("PinkBall");


			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			//cvtColor(cameraFeed,HSV,COLOR_BGR2YCrCb);
			inRange(HSV,BlueRock.getHSVmin(),BlueRock.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(BlueRock,threshold,HSV,cameraFeed);

			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			//cvtColor(cameraFeed,HSV,COLOR_BGR2YCrCb);
			inRange(HSV,RedPuck.getHSVmin(),RedPuck.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(RedPuck,threshold,HSV,cameraFeed);

			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			//cvtColor(cameraFeed,HSV,COLOR_BGR2YCrCb);
			inRange(HSV,OrangePipe.getHSVmin(),OrangePipe.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(OrangePipe,threshold,HSV,cameraFeed);

			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			//cvtColor(cameraFeed,HSV,COLOR_BGR2YCrCb);
			inRange(HSV,PinkBall.getHSVmin(),PinkBall.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(PinkBall,threshold,HSV,cameraFeed);

		}

		//show frames 
		//imshow(windowName2,threshold);

		imshow(windowName,cameraFeed);
		//imshow(windowName1,HSV);


		//delay 30ms so that screen can refresh.
		//image will not appear without this waitKey() command
		waitKey(30);
	}






	return 0;
}
int main(int argc, char* argv[])
{
	//if we would like to calibrate our filter values, set to true.
	bool calibrationMode = true;
	
	//Matrix to store each frame of the webcam feed
	Mat cameraFeed;
	Mat threshold;
	Mat HSV;

	if(calibrationMode){
		//create slider bars for HSV filtering
		createTrackbars();
	}
	//video capture object to acquire webcam feed
	VideoCapture capture;
	//open capture object at location zero (default location for webcam)
	capture.open(0);
	//set height and width of capture frame
	capture.set(CV_CAP_PROP_FRAME_WIDTH,FRAME_WIDTH);
	capture.set(CV_CAP_PROP_FRAME_HEIGHT,FRAME_HEIGHT);
	//start an infinite loop where webcam feed is copied to cameraFeed matrix
	//all of our operations will be performed within this loop
	while(1){
		//store image to matrix
		capture.read(cameraFeed);
		//convert frame from BGR to HSV colorspace
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);

		if(calibrationMode==true){
		//if in calibration mode, we track objects based on the HSV slider values.
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
		inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold);
		morphOps(threshold);
		imshow(windowName2,threshold);
		trackFilteredObject(threshold,HSV,cameraFeed);
		}else{
		//create some temp fruit objects so that
		//we can use their member functions/information
		Fruit apple("apple"), banana("banana"), cherry("cherry");

		
		//first find apples
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
		inRange(HSV,apple.getHSVmin(),apple.getHSVmax(),threshold);
		morphOps(threshold);
		trackFilteredObject(apple,threshold,HSV,cameraFeed);
		//then bananas
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
		inRange(HSV,banana.getHSVmin(),banana.getHSVmax(),threshold);
		morphOps(threshold);
		trackFilteredObject(banana,threshold,HSV,cameraFeed);
		//then cherries
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
		inRange(HSV,cherry.getHSVmin(),cherry.getHSVmax(),threshold);
		morphOps(threshold);
		trackFilteredObject(cherry,threshold,HSV,cameraFeed);



		}

		//show frames 
		//imshow(windowName2,threshold);

		imshow(windowName,cameraFeed);
		//imshow(windowName1,HSV);


		//delay 30ms so that screen can refresh.
		//image will not appear without this waitKey() command
		waitKey(30);
	}






	return 0;
}
bool ShapesDetector::scan_colour(Mat HSV_img,HSV_Param Filt_Type, int thres) {
    cv::Mat threshold;
    int xPos,yPos;
    int x_min_box = thres;
    int x_max_box = FRAME_WIDTH-thres;
    int y_min_box = thres;
    int y_max_box = FRAME_HEIGHT-thres;
    Shape tempShape;
    vector<Shape> tempShapes;

    //initiallize temp shape with color
    tempShape.setColour(Filt_Type.getColour());

    //initiallize box constraints
    if(thres < 0) {
        x_min_box = CENTER_BOX_X_MIN;
        x_max_box = CENTER_BOX_X_MAX;
        y_min_box = CENTER_BOX_Y_MIN;
        y_max_box = CENTER_BOX_Y_MAX;
    }

    cv::inRange(HSV_img,Filt_Type.getHSVmin(),Filt_Type.getHSVmax(),threshold);

    if(Filt_Type.getColour() == red) {
        cv::Mat temp;
        cv::Scalar HSV_min = Filt_Type.getHSVmin();
        cv::Scalar HSV_max = Filt_Type.getHSVmax();

        HSV_min.val[0] = RED_H_MIN_2;
        HSV_max.val[0] = RED_H_MAX_2;

        cv::inRange(HSV_img,HSV_min,HSV_max,temp);
        bitwise_or(threshold, temp, threshold);

        //cv::imshow("red threshold",threshold);
        //waitKey(50);
    }

    morphOps(threshold);

    //these two vectors needed for output of findContours
    vector< vector<Point> > contours;
    cv::Mat approx;
    cv::Mat edges_map;
    vector<Vec4i> hierarchy;
    vector<Vec3f> circles;
    //find contours of filtered image using openCV findContours function
    cv::findContours(threshold,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
    //cv::Canny(threshold, edges_map, 5, 250, 7, true);
    //cv::HoughCircles(edges_map, circles, CV_HOUGH_GRADIENT, 1, 100, 180, 30 ,20, 210);

    //use moments method to find the position
    double refArea = 0;
    bool objectFound = false;
    if (hierarchy.size() > 0) {
        int numObjects = hierarchy.size();
        //if number of objects greater than MAX_NUM_OBJECTS we have a noisy filter
        if(numObjects<MAX_NUM_OBJECTS) {
            for (int index = 0; index >= 0; index = hierarchy[index][0]) {

                Moments moment = moments((cv::Mat)contours[index]);
                double area = moment.m00;

                //if the area is less than 20 px by 20px then it is probably just noise
                //if the area is the same as the 3/2 of the image size, probably just a bad filter
                //we only want the object with the largest area so we safe a reference area each
                //iteration and compare it to the area in the next iteration.
                if(area>MIN_OBJECT_AREA) {

                    approxPolyDP(Mat(contours[index]), approx, arcLength(Mat(contours[index]), true)*0.04, true);
                    drawContours(img_info, approx, -1, Scalar(0,255,0), 5, 4);

                    xPos = moment.m10/area;
                    yPos = moment.m01/area;

                    tempShape.setXPos(xPos);
                    tempShape.setYPos(yPos);

                    int corners = approx.size().height;

                    if(corners == 3) {
                        tempShape.setShape(triangle_sh);
                    } else if(corners == 4) {
                        tempShape.setShape(square_sh);
                    } else if(corners > 5) {
                        tempShape.setShape(circle_sh);
                    }

                    if(corners >= 3) {
                        tempShapes.push_back(tempShape);
                    }

                }


            }

        }
    }

    /*//ROS_INFO("Circles Detected: %d",circles.size());

    for( size_t i = 0; i < circles.size(); i++ ) {
    	tempShape.setXPos(cvRound(circles[i][0]));
    	tempShape.setYPos(cvRound(circles[i][1]));

    	tempShape.setRadius(cvRound(circles[i][2]));

    	tempShape.setShape(circle_sh);

    	tempShapes.push_back(tempShape);
    }*/

    for( size_t i = 0; i < tempShapes.size(); i++ ) {
        int xPos = tempShapes[i].getXPos();
        int yPos = tempShapes[i].getYPos();

        if((xPos < x_max_box && xPos > x_min_box) && (yPos < y_max_box && yPos > y_min_box)) {
            Shapes.push_back(tempShapes[i]);
        }
    }

    return true;
}
int main(int argc, char* argv[])
{
	//if we would like to calibrate our filter values, set to true.
	bool calibrationMode = true;

	//Matrix to store each frame of the webcam feed
	Mat cameraFeed;
	Mat threshold;
	Mat HSV;

	if(calibrationMode){
		//create slider bars for HSV filtering
		createTrackbars();
	}
	//video capture object to acquire webcam feed
	VideoCapture capture;
	//open capture object at location zero (default location for webcam)
	capture.open(0);
	//set height and width of capture frame
	capture.set(CV_CAP_PROP_FRAME_WIDTH,FRAME_WIDTH);
	capture.set(CV_CAP_PROP_FRAME_HEIGHT,FRAME_HEIGHT);
	//start an infinite loop where webcam feed is copied to cameraFeed matrix
	//all of our operations will be performed within this loop
	waitKey(1000);
	while(1){
		//store image to matrix
		capture.read(cameraFeed);

		src = cameraFeed;

  		if( !src.data )
  		{ return -1; }

		//convert frame from BGR to HSV colorspace
		cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);

		if(calibrationMode==true){

		//need to find the appropriate color range values
		// calibrationMode must be false

		//if in calibration mode, we track objects based on the HSV slider values.
			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			inRange(HSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),threshold);
			morphOps(threshold);
			imshow(windowName2,threshold);

		//the folowing for canny edge detec
			/// Create a matrix of the same type and size as src (for dst)
	  		dst.create( src.size(), src.type() );
	  		/// Convert the image to grayscale
	  		cvtColor( src, src_gray, CV_BGR2GRAY );
	  		/// Create a window
	  		namedWindow( window_name, CV_WINDOW_AUTOSIZE );
	  		/// Create a Trackbar for user to enter threshold
	  		createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold);
	  		/// Show the image
			trackFilteredObject(threshold,HSV,cameraFeed);
		}
		else{
			//create some temp fruit objects so that
			//we can use their member functions/information
			Object blue("blue"), yellow("yellow"), red("red"), green("green");

			//first find blue objects
			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			inRange(HSV,blue.getHSVmin(),blue.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(blue,threshold,HSV,cameraFeed);
			//then yellows
			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			inRange(HSV,yellow.getHSVmin(),yellow.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(yellow,threshold,HSV,cameraFeed);
			//then reds
			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			inRange(HSV,red.getHSVmin(),red.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(red,threshold,HSV,cameraFeed);
			//then greens
			cvtColor(cameraFeed,HSV,COLOR_BGR2HSV);
			inRange(HSV,green.getHSVmin(),green.getHSVmax(),threshold);
			morphOps(threshold);
			trackFilteredObject(green,threshold,HSV,cameraFeed);

		}
		//show frames
		//imshow(windowName2,threshold);

		imshow(windowName,cameraFeed);
		//imshow(windowName1,HSV);

		//delay 30ms so that screen can refresh.
		//image will not appear without this waitKey() command
		waitKey(30);
	}
	return 0;
}