-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at experimental code to split and threshold image.
Image captured by webcam is split into three components, and the green channel is thresholded to identify the green LEDs.
- Loading branch information
James Ward
committed
Sep 9, 2013
1 parent
6259fb7
commit 05017f5
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import cv2 as cv | ||
|
||
cv.namedWindow("preview") | ||
vc = cv.VideoCapture(-1) | ||
|
||
if vc: # try to get the first frame | ||
vc.set(cv.cv.CV_CAP_PROP_FRAME_WIDTH, 640) | ||
vc.set(cv.cv.CV_CAP_PROP_FRAME_HEIGHT, 480) | ||
retval, frame = vc.read() | ||
|
||
while retval: | ||
# Split the frame into components. | ||
green_img = cv.split(frame)[1] | ||
|
||
# Find the maximum pixel value in the green image. | ||
[minVal, maxVal, minLoc, maxLoc] = cv.minMaxLoc(green_img) | ||
|
||
# Don't show anything below this fraction of the max pixel value. Trial and error. | ||
margin = 0.92 | ||
|
||
# Threshold value in pix value to be extracted | ||
thresh = int( maxVal * margin) | ||
|
||
# Do the thresholding. | ||
retval, thresh_img = cv.threshold(green_img, thresh, 255, cv.cv.CV_THRESH_BINARY) | ||
|
||
# Show the result | ||
cv.imshow("preview", thresh_img) | ||
|
||
# Get the next frame | ||
retval, frame = vc.read() | ||
|
||
key = cv.waitKey(20) | ||
if key != -1: # exit on any key | ||
break | ||
# Loop forever... |