Two part assignment.
Using Python and OpenCV you need to do the following two parts (Should be two different applications).
Part One:
Tracking an object
Steps to do it properly…..
- Capture live video from Webcam
- Display live video
- convert BGR to HSV
- Display the HSV video
- Click on HSV video and capture the HSV values at the location clicked, and a few other local values of the item you are going to track.
- use a MouseCallback to print the HSV values.
- Using Sliders create scalers for the min and max values you want to track
- a Scalar will be a numpy array (np.array) that takes 3 values for minH, minS, and minV…….then a second scalar to catch the other three Max values
- create 6 trackbars, createTrackbar with callback methods to set your six variables
- Us the OpenCV inRange method to find the values between the scalars from HSV image and the result will go to a grayscale image (make it a binary image, white/black).
- Dilate, erode the grayscale image to get a better representation of the object you are tracking.
- Display the original image and the binary image where everything is black except for the object you are tracking. The tracked object will be white.
Done Part One….
Part Two
Detect Motion
- Capture an image
- Create blank images:
- grayscale image with proper dimensions
- 32f, 3 channel image
- a capture clone we’ll call image1
- One to hold the result from the absDiff function. (absolute difference)
- while loop to capture images……
- grab new frame
- I brightened image a bit first which helped
- blur the image
- take running average of frame: accumulateWeighted
- swap running average result from step 6 to same bits as frame: convertScaleAbs
- Take difference, built in OpenCV function to do a diff between two images.
- convert to grayscale
- Threshhold grayscale (using a low number)
- Blur grayscale image
- Threshhold grayscale again (using a high number)
- find contours: findContours
- Use contours to find significant blobs,
- draw polygons of blobs
- use dimensions of blobs to draw bounding boxes and center on original image
Done