zoukankan      html  css  js  c++  java
  • python-----opencv读视频、循环读图片显示进度条

    功能:opencv读视频,显示进度条,推动进度条快进、后退,按q退出。代码如下:

    import os
    import cv2
    def nothing(emp):
        pass
    def jindu(name,video):
        cv2.namedWindow(name,0)
        cv2.resizeWindow(name, 800, 600)
        cap = cv2.VideoCapture(video)
        frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
        loop_flag = 0
        pos = 0
        cv2.createTrackbar('time', name, 0, frames, nothing)
    
        while 1:
            if loop_flag == pos:
                loop_flag = loop_flag + 1
                cv2.setTrackbarPos('time', name, loop_flag)
                print('loop_flag1', loop_flag)
            else:
                pos = cv2.getTrackbarPos('time', name)
                loop_flag = pos
                cap.set(cv2.CAP_PROP_POS_FRAMES, pos)
                print('loop_flag2', loop_flag)
            ret, img = cap.read()
    
            cv2.imshow(name, img)
            if cv2.waitKey(1) & 0xFF == ord('q'): #按q退出
                cv2.waitKey(0)
    
    if __name__ == '__main__':
        video = r"D:Team-CVvideo_wang	est/1.MOV"
        name = video.split('.')[-1]
        jindu(name, video)

    功能:opencv循环读图片,显示进度条,推动进度条快进、后退,按q退出。代码如下:

    import os
    import cv2
    def nothing(emp):
        pass
    
    def jindu_imgpath(name,frames):
        cv2.namedWindow(name,0)
        cv2.resizeWindow(name, 800, 600)
        loop_flag = 0
        pos = 0
        cv2.createTrackbar('time', name, 0, frames, nothing)
        path_list = os.listdir(img_path)
        for m, img in enumerate(path_list):
            img_file = img_path + '/' + img
            img_new = cv2.imread(img_file)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                cv2.waitKey(0)
            if loop_flag == pos:
                loop_flag = loop_flag + 1
                cv2.setTrackbarPos('time', name, loop_flag)
            else:
                pos = cv2.getTrackbarPos('time', name)
                loop_flag = pos
            img = path_list[loop_flag]
            img_file = img_path + '/' + img
            img_new = cv2.imread(img_file)
            cv2.imshow(name, img_new)
    
    if __name__ == '__main__':
        img_path = r"D:Team-CVvideo_wang	estJPEGImages"
        frames = len(os.listdir(img_path))
        jindu_imgpath('img', frames)
  • 相关阅读:
    ueditor1.4.3.all.js报错
    ueditor中FileUtils.getTempDirectory()找不到
    java后台验证码的生成
    applicationContext.xml重要配置
    Java代码实现文件上传(转载)
    jquery动态实现填充下拉框
    POI写入word docx 07 的两种方法
    POI读word docx 07 文件的两种方法
    POI转换word doc文件为(html,xml,txt)
    Linux中zip压缩和unzip解压缩命令详解
  • 原文地址:https://www.cnblogs.com/xiaodai0/p/10247403.html
Copyright © 2011-2022 走看看