Beispiel #1
0
def create_thumb(file_path):
    import sins.module.cv as cv2
    from sins.utils.const import VIDEO_EXT, IMG_EXT, THUMB_MAX_CACHE_FRAMES, THUMB_FIXED_WIDTH
    from sins.utils.io.opencv import CacheThread, ReadThread

    if os.path.splitext(file_path)[1] in VIDEO_EXT:
        cap = cv2.VideoCapture(file_path)
        frame_num = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
        step = 1
        if frame_num > THUMB_MAX_CACHE_FRAMES:
            step = int(frame_num / THUMB_MAX_CACHE_FRAMES)

        thread = CacheThread(capFile=file_path,
                             cap=cap,
                             fixwidth=THUMB_FIXED_WIDTH,
                             frameIn=1,
                             frameOut=frame_num,
                             step=step,
                             tocache=True)
        thread.start_cache()
    elif os.path.splitext(file_path)[1] in IMG_EXT:
        thread = ReadThread(readFile=file_path,
                             fixwidth=THUMB_FIXED_WIDTH
                            )
        thread.start_cache()
Beispiel #2
0
    def __init__(self,
                 capFile,
                 cap=None,
                 frameIn=1,
                 frameOut=None,
                 step=1,
                 fix_length=True,
                 resize=1,
                 fixwidth=None,
                 readcache=False,
                 tocache=False):
        super(CacheThread, self).__init__()

        self.capFile = capFile
        self.step = step
        self.fix_length = fix_length
        self.resizeRatio = resize
        self.fixWidth = fixwidth
        self.readcache = readcache
        self.tocache = tocache

        self.index = 0

        if cap is None:
            self.cap = cv2.VideoCapture(capFile)
        else:
            self.cap = cap
        self.frameNum = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))
        self.frameIn = frameIn
        self.frameOut = frameOut if frameOut is not None else self.frameNum
        self.frameW = self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)
        self.frameH = self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

        self.cacheFrames = {}
Beispiel #3
0
 def load_capture(self, capFile):
     # print capFile
     self.capfile = capFile
     self.cap = cv2.VideoCapture(capFile)
     self.frameNum = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))
     self.capRatio = self.cap.get(cv2.CAP_PROP_FRAME_WIDTH) / self.cap.get(
         cv2.CAP_PROP_FRAME_HEIGHT)
     if self.dynamic:
         self.cache_cap(capFile)
     else:
         self.read_file(capFile)
Beispiel #4
0
    def __init__(self,
                 readFile,
                 cap=None,
                 frame=1,
                 fixwidth=None,
                 readcache=True):
        super(ReadThread, self).__init__()

        self.readFile = readFile
        self.fixWidth = fixwidth
        self.readcache = readcache
        if os.path.splitext(readFile)[1] in VIDEO_EXT:
            if cap is None:
                self.cap = cv2.VideoCapture(readFile)
            else:
                self.cap = cap
            self.frame = frame

        self.cacheFile = os.path.abspath(self.readFile) + ".thumbnail"
Beispiel #5
0
    def load_capture(self, capFile):
        self.cap = cv2.VideoCapture(capFile)
        self.fps = int(self.cap.get(cv2.CAP_PROP_FPS))
        self.frameNum = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))

        self.cache_cap(capFile)

        self.fpsEdit.set_origin_fps(self.fps)
        self.frameInEdit.setText(str(1))
        self.frameOutEdit.setText(str(self.frameNum))
        self.frameIn = 1
        self.frameOut = self.frameNum
        self.customFrameIn = 1
        self.customFrameOut = self.frameNum
        self.playSlider.setMinimum(1)
        self.playSlider.setMaximum(self.frameNum)
        self.playSlider.frameOut = self.frameNum
        self.capRatio = float(self.cap.get(
            cv2.CAP_PROP_FRAME_WIDTH)) / self.cap.get(
                cv2.CAP_PROP_FRAME_HEIGHT)
        self.cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
        self.currentFrame = 1