获取图像高度和宽度,并初始化文字字体,在 1/2 高度处写入“3100102592 menglixia”的字符串,以颜色红色(在二值化后的图像中显示为 黑色)
5. 显示每一帧图像:
cv.ShowImage("camera",img)
#coding=utf-8
import cv2.cv as cv
def binaryThreshold(Image, threshold):
grey = cv.CreateImage(cv.GetSize(img),cv.IPL_DEPTH_8U, 1)
out = cv.CreateImage(cv.GetSize(img),cv.IPL_DEPTH_8U, 1)
cv.CvtColor(Image,grey,cv.CV_BGR2GRAY)
cv.Threshold(grey, out ,threshold , 255 ,cv.CV_THRESH_BINARY)
return out
if __name__ == '__main__':
#threshold = input("threshold=")
cv.NamedWindow("camera",1)
capture = cv.CaptureFromCAM(0)
while True:
""" capture image from camera """
img = cv.QueryFrame(capture)
""" convert color image to grey """
#img = binaryThreshold(img