示例#1
0
def show_video(fileorid):
    cv.namedWindow(str(fileorid), cv.CV_WINDOW_AUTOSIZE)
    video = cv.VideoCapture(fileorid) 
    img = cv.Mat() 
    img2 = cv.Mat()    
    while video.grab():     
        video.retrieve(img, 0) 
        #cv.cvtColor(img, img2, cv.CV_GBR2RGB)
        cv.imshow(str(fileorid), img)
        cv.waitKey(5)
示例#2
0
def show_video(fileorid):
    cv.namedWindow(str(fileorid), cv.CV_WINDOW_AUTOSIZE)
    video = cv.VideoCapture(fileorid) 
    img = cv.Mat() 
    img2 = cv.Mat()    
    while video.grab():     
        video.retrieve(img, 0) 
        #cv.cvtColor(img, img2, cv.CV_GBR2RGB)
        cv.imshow(str(fileorid), img)
        cv.waitKey(5)
def blend(img, img2): 
    """
    混合两幅图像, 其中img2有4个通道
    """
    #使用alpha通道计算img2的混和值
    b = img2[:,:,3:] / 255.0     
    a = 1 - b # img的混合值

    #混合两幅图像
    img[:,:,:3] *= a  
    img[:,:,:3] += b * img2[:,:,:3]

img2[:] = 0
for i in xrange(0, w, w/10): 
    cv.line(img2, cv.Point(i,0), cv.Point(i, h),  
        cv.Scalar(0, 0, 255, i*255/w), 5)

blend(img, img2) 

img2[:] = 0        
for i in xrange(0, h, h/10):
    cv.line(img2, cv.Point(0,i), cv.Point(w, i), 
        cv.Scalar(0, 255, 0, i*255/h), 5)
        
blend(img, img2)
     
cv.namedWindow("Draw Demo")
cv.imshow("Draw Demo", img)
cv.waitKey(0)
示例#4
0
import numpy as np
import pyopencv as cv2

# Load an color image in grayscale
img = cv2.imread('IMG.jpeg', 0)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('1.png', img)
示例#5
0
import numpy as np
import pyopencv as cv2

# Load an color image in grayscale
img = cv2.imread('IMG.jpeg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('1.png', img)
    winName = 'PyOpenCV fun'

    cascade = pyopencv.CascadeClassifier()
    cascade.load("haarcascades/haarcascade_mcs_eyepair_big.xml")

    fallbackCascade = pyopencv.CascadeClassifier()
    fallbackCascade.load("haarcascades/haarcascade_mcs_eyepair_small.xml")

    glasses = Image.open('darkkamina.png')
    glasses.load()

    capture = pyopencv.VideoCapture()
    frame = pyopencv.Mat()
    capture.open(1)
    pyopencv.namedWindow(winName, pyopencv.CV_WINDOW_AUTOSIZE&1)

    if capture.isOpened():
        while True:
            capture.retrieve(frame)
            if frame.empty():
                break

            eyes = detect(frame, cascade, fallbackCascade)
            final = draw(frame, eyes, glasses)

            pyopencv.imshow(winName, final)

            if pyopencv.waitKey(25) >= 0:
                break

if __name__ == '__main__':
    cv.namedWindow('foo', 1)
#    src = load_image('/Users/ross/Programming/demo/lena.jpg', swap=True)
    src = load_image('/Users/ross/Programming/demo/lena.jpg', swap=True)
#    draw_point(src, (100, 100))
    gsrc = grayspace(src)
    tsrc = threshold(gsrc, 100)
    csrc = colorspace(tsrc)
#    gsrc = src
#    conts, hierarchy = contour(tsrc)
# #
#    print get_polygons(conts)

    draw_lines(csrc, [[(0, 0), (100, 100)]])
    cv.imshow('foo', csrc)
    c = cv.waitKey(0)
#    if(c & 255 == 27):
#        break
#======== EOF ===================================================
# def new_dst(src, zero=False, width=None,
#            height=None, nchannels=None, size=None):
#    '''
#    '''
#
# #    print nchannels
#    if width is not None and height is not None:
#        size = cv.Size(width, height)
#    elif size is None:
#        size = cv.getSize(src)
#
#    if nchannels is None: