1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
import sys
import urllib2
import cv
# some definitions
win_name = "Edge"
trackbar_name = "Threshold"
# the callback on the trackbar
def on_trackbar(position):
cv.Smooth(gray, edge, cv.CV_BLUR, 3, 3, 0)
cv.Not(gray, edge)
# run the edge dector on gray scale
cv.Canny(gray, edge, position, position * 3, 3)
# reset
cv.SetZero(col_edge)
# copy edge points
cv.Copy(im, col_edge, edge)
# show the im
cv.ShowImage(win_name, col_edge)
im = cv.LoadImage("Tv25.tif", cv.CV_LOAD_IMAGE_COLOR)
# create the output im
col_edge = cv.CreateImage((im.width, im.height), 8, 3)
# convert to grayscale
gray = cv.CreateImage((im.width, im.height), 8, 1)
edge = cv.CreateImage((im.width, im.height), 8, 1)
cv.CvtColor(im, gray, cv.CV_BGR2GRAY)
# create the window
cv.NamedWindow(win_name, cv.CV_WINDOW_AUTOSIZE)
# create the trackbar
cv.CreateTrackbar(trackbar_name, win_name, 1, 100, on_trackbar)
# show the im
on_trackbar(0)
# wait a key pressed to end
cv.WaitKey(0) |
Partager