美文网首页
opencv fun: 蓝线特效

opencv fun: 蓝线特效

作者: 1037号森林里一段干木头 | 来源:发表于2021-01-09 19:01 被阅读0次

    简介:开始是在b站上看到很多蓝线特效视频很搞笑,在手机应用商店里面没找到类似的软件,所以就手动写一个在笔记本上玩玩。下面的代码很短,麻雀虽小五脏俱全呐。

    1. 效果:


      蓝线特效.gif
    2. 代码:

    import cv2
    import numpy as np
    
    def blueLineUpToDown(speed=3):
        cap = cv2.VideoCapture(0)
        ret,frame = cap.read()
        finalImage = np.zeros(frame.shape,np.uint8)
        line = 0
    
        while (1):
            ret,frame = cap.read()
            line += speed
            if line >= finalImage.shape[0]:
                break
    
            finalImage[line:,:] = frame[line:,:]
            cv2.line(finalImage,(0,line+2*speed),(finalImage.shape[1],line+2*speed),(0,255,0),2)
            cv2.imshow("img",finalImage)
            #cv2.imshow("frame",frame)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break
    
        cap.release()
        cv2.destroyAllWindows()
        cv2.imshow("final",finalImage)
        #cv2.imwrite("./img.png",finalImage)
        cv2.waitKey(0)
        cv2.destroyWindow("final")
        
    def blueLineLeftToRight(speed=3):
        cap = cv2.VideoCapture(0)
        ret,frame = cap.read()
        finalImage = np.zeros(frame.shape,np.uint8)
        line = 0
    
        while (1):
            ret,frame = cap.read()
            line += speed
            if line >= finalImage.shape[1]:
                break
    
            finalImage[:,line:] = frame[:,line:]
            cv2.line(finalImage,(line+2*speed,0),(line+2*speed,finalImage.shape[1]),(0,255,0),2)
            cv2.imshow("img",finalImage)
            #cv2.imshow("frame",frame)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break
    
        cap.release()
        cv2.destroyAllWindows()
        cv2.imshow("final",finalImage)
        #cv2.imwrite("./img.png",finalImage)
        cv2.waitKey(0)
        cv2.destroyWindow("final")
        
    if __name__ == "__main__":
        speed = 1 
        mode = 1
        if mode ==0:
            blueLineUpToDown(speed) 
        else:
            blueLineLeftToRight(speed)
    

    相关文章

      网友评论

          本文标题:opencv fun: 蓝线特效

          本文链接:https://www.haomeiwen.com/subject/wjocaktx.html