python类VideoWriter()的实例源码

log_face_people_detection.py 文件源码 项目:spqrel_tools 作者: LCAS 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, IP, PORT, CameraID, parent=None):
        """
        Initialization.
        """

        self._image = None


        self._imgWidth = 320
        self._imgHeight = 240
        self._cameraID = CameraID


        # Proxy to ALVideoDevice.
        self._videoProxy = None

        # Our video module name.
        self._imgClient = ""

        # This will contain this alImage we get from Nao.
        self._alImage = None

        self._registerImageClient(IP, PORT)

        # Trigger 'timerEvent' every ms.
        self.delay=0.05

        self.output_path='./data/'+datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')+'/'
        # Define the codec and create VideoWriter object
        self.enabledwriter=False
        self._fps=2.0
        self.outvideo=self.output_path+'log.avi'
        self._fourcc = cv2.cv.FOURCC(*'XVID')
        self._out =None
        self.numframe=0
log_face_people_detection.py 文件源码 项目:spqrel_tools 作者: LCAS 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def initWriter(self):

        if not os.path.exists(self.output_path):
            os.makedirs(self.output_path)
        self._out = cv2.VideoWriter(self.outvideo, self._fourcc, self._fps, (self._imgWidth,self._imgHeight))
        self.enabledwriter=True
agent_a3c.py 文件源码 项目:rl_3d 作者: avdmitry 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def Test(agent):
    if (test_write_video):
        size = (640, 480)
        fps = 30.0
        fourcc = cv2.VideoWriter_fourcc(*'XVID')  # cv2.cv.CV_FOURCC(*'XVID')
        out_video = cv2.VideoWriter(path_work_dir + "test.avi", fourcc, fps, size)

    reward_total = 0
    num_episodes = 30
    while (num_episodes != 0):
        if (not env.IsRunning()):
            env.Reset()
            agent.Reset()
            print("Total reward: {}".format(reward_total))
            reward_total = 0
            num_episodes -= 1

        state_raw = env.Observation()

        state = Preprocess(state_raw)
        action = agent.Act(state)

        for _ in xrange(frame_repeat):
            if (test_display):
                cv2.imshow("frame-test", state_raw)
                cv2.waitKey(20)

            if (test_write_video):
                out_video.write(state_raw)

            reward = env.Act(action, 1)
            reward_total += reward

            if (not env.IsRunning()):
                break

            state_raw = env.Observation()
agent_dqn.py 文件源码 项目:rl_3d 作者: avdmitry 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def Test(agent):
    if (test_write_video):
        size = (640, 480)
        fps = 30.0 #/ frame_repeat
        fourcc = cv2.VideoWriter_fourcc(*'XVID')  # cv2.cv.CV_FOURCC(*'XVID')
        out_video = cv2.VideoWriter(path_work_dir + "test.avi", fourcc, fps, size)

    reward_total = 0
    num_episodes = 30
    while (num_episodes != 0):
        if (not env.IsRunning()):
            env.Reset()
            print("Total reward: {}".format(reward_total))
            reward_total = 0
            num_episodes -= 1

        state_raw = env.Observation()

        state = Preprocess(state_raw)
        action = agent.GetAction(state)

        for _ in xrange(frame_repeat):
            # Display.
            if (test_display):
                cv2.imshow("frame-test", state_raw)
                cv2.waitKey(20)

            if (test_write_video):
                out_video.write(state_raw)

            reward = env.Act(action, 1)
            reward_total += reward

            if (not env.IsRunning()):
                break

            state_raw = env.Observation()
camera.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, index=0):
        self.frame = None
        self.capture = cv2.VideoCapture(0)
        self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
        self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
        # self.capture.set(cv2.CAP_PROP_EXPOSURE, 0)
        # self.capture.set(cv2.CAP_PROP_GAIN, 0)

        # Define codec and create VideoWriter object
        # fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
        # self.out = cv2.VideoWriter('output.avi', fourcc, 120.0, (640, 480))
video.py 文件源码 项目:learning-blind-motion-deblurring 作者: cgtuebingen 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, fn, height, width, channels=3, fps=30):
        super(Writer, self).__init__()
        self.width = width
        self.height = height
        self.channels = channels
        self.fn = fn
        print("writing to %s with shape (%i, %i, %i)" % (fn, height, width, channels))

        cc4 = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
        self.out = cv2.VideoWriter(fn, cc4, fps, (width, height), isColor=(channels == 3))
visualize.py 文件源码 项目:dsde-deep-learning 作者: broadinstitute 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_video_writer(args):
    # Define the codec and create VideoWriter object
    #fourcc = cv2.VideoWriter_fourcc(*'XVID')
    fourcc = cv2.VideoWriter_fourcc('P','I','M','1')
    return cv2.VideoWriter(args.video_path, fourcc, args.fps, (args.width, args.height))
video_tool.py 文件源码 项目:mlAlgorithms 作者: gu-yan 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def image2video():
    video_writer = cv2.VideoWriter(filename=args.videopath,
                                   fourcc=cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'),
                                   fps=args.videofps, frameSize=(videosize[0], videosize[1]))
    list = os.listdir(args.imagepath)
    list.sort()
    for jpg in list:
        video_writer.write(cv2.imread(os.path.join(args.imagepath, jpg)))
    video_writer.release()
optical_flow_double.py 文件源码 项目:vizgen 作者: uva-graphics 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def main():
    if Display:
        cap = cv2.VideoCapture(0)
        out = cv2.VideoWriter('output.avi', -1, 2.0, (600, 440))
        count = 0

        while(count < 20):
            ret, frame1 = cap.read()
            ret, frame2 = cap.read()

            frame1 = skimage.img_as_float(frame1)
            frame2 = skimage.img_as_float(frame2)

            output_img = optical_flow_ssd(frame1, frame2)
            out.write(output_img)

            cv2.imshow('frame', output_img)
            count = count + 1

            if cv2.waitKey(1) & 0xFF == ord('q'):
                cap.release()
                out.release()
                cv2.destroyAllWindows()
                break
    else:
        test()
simulation.py 文件源码 项目:trackingtermites 作者: dmrib 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, config_path):
        self.termites = []
        self.params = utils.read_config_file(config_path)
        self.simulation_speed = self.params['simulation_speed']
        self.out = cv2.VideoWriter('{}simulation-out.avi'.format(self.params['output_path']),
                                   cv2.VideoWriter_fourcc(*'XVID'), 30.0,
                                   (1280,480))
video.py 文件源码 项目:trackingtermites 作者: dmrib 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, video_path, out_path, video_shape, filters, write_capture_info, subtractor='MOG'):
        """Initializer.

        Args:
            video_path (str): path to video file.
            out_path (str): output video destination path.
            video_shape (tuple): default size for frame redimensioning.
            filters (list): list of filter's names to apply in video source.
            write_info (bool): should write frame info when displaying.
            subtractor (str): name of background subtractor.
        Returns:
            None.
        """
        if video_path == '-1':
            video_path = int(video_path)
        self.source = cv2.VideoCapture(video_path)
        if not self.source.isOpened():
            print('Could not find video file.')
            sys.exit()

        if subtractor == 'MOG':
            self.subtractor = cv2.createBackgroundSubtractorMOG2()
        elif subtractor == 'GMG':
            self.subtractor = cv2.bgsegm.createBackgroundSubtractorGMG()

        self.current_frame = None
        self.playing = False
        self.video_shape = video_shape
        self.codec = cv2.VideoWriter_fourcc(*'XVID')
        self.out = cv2.VideoWriter('{}tracking-out.avi'.format(out_path),
                                   self.codec, 30.0, self.video_shape)
        self.filters = filters
        self.write_capture_info = write_capture_info
        self.start()
main.py 文件源码 项目:Computer-Vision 作者: PratikRamdasi 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def writeVideo(self):
        height,width=cv2.imread("Frames/1.jpg").shape[:2]
        out = cv2.VideoWriter("changedOutput.ogv",cv.CV_FOURCC('t','h','e','0'), 25.0, (width,height))
        folder=self.sort_files()

        for i in folder:
            pic="Frames/"+str(i)+".jpg"
            img=cv2.imread(pic) 
            out.write(img)
        out.release()
main.py 文件源码 项目:Computer-Vision 作者: PratikRamdasi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def writeVideo(self):
        height,width=cv2.imread("Frames/1.jpg").shape[:2]
        out = cv2.VideoWriter("changedOutput.ogv",cv.CV_FOURCC('t','h','e','0'), 25.0, (width,height))
        folder=self.sort_files()

        for i in folder:
            pic="Frames/"+str(i)+".jpg"
            img=cv2.imread(pic) 
            out.write(img)
        out.release()
videoWriter.py 文件源码 项目:Computer-Vision 作者: PratikRamdasi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def writeOutputFile(self):
        self.height,self.width=cv2.imread("/Users/pratikramdasi/Desktop/frames/0 (1).jpg").shape[:2]
        out = cv2.VideoWriter("/Users/pratikramdasi/Desktop/vtest.mp4",cv.CV_FOURCC('a','v','c','1'), 30.0, (self.width, self.height))
        folder=self.sort_files()

        for i in folder:
            pic="/Users/pratikramdasi/Desktop/frames/0 ("+str(i)+").jpg"
            img=cv2.imread(pic)
            out.write(img)
        out.release()
videoTransforms.py 文件源码 项目:Computer-Vision 作者: PratikRamdasi 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def writeOutputFile(self,output):
        self.height,self.width=cv2.imread("Frames/1.jpg").shape[:2]
        out = cv2.VideoWriter(output,cv.CV_FOURCC('a','v','c','1'), 30.0, (self.width, self.height))
        folder=self.sort_files()

        for i in folder:
            pic="Frames/"+str(i)+".jpg"
            img=cv2.imread(pic) 
            out.write(img)
        out.release()

    # Method to sort the files (here, frames!)
recorder.py 文件源码 项目:recorder 作者: baxter-flowers 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def open_writer(self, camera):
        if self.cameras_enabled[camera] and not self.writers[camera]:
            self.writers[camera] = VideoWriter(path + '/' + camera + self.extension,
                                               self.four_cc, self.rate_hz,
                                               (self.image[camera].width, self.image[camera].height),
                                               isColor=camera != 'depth')
musecube_old.py 文件源码 项目:PyMUSE 作者: ismaelpessa 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def make_video(self, images, outimg=None, fps=2, size=None, is_color=True, format="XVID", outvid='image_video.avi'):
        from cv2 import VideoWriter, VideoWriter_fourcc, imread, resize
        fourcc = VideoWriter_fourcc(*format)
        vid = None
        for image in images:
            if not os.path.exists(image):
                raise FileNotFoundError(image)
            img = imread(image)
            if vid is None:
                if size is None:
                    size = img.shape[1], img.shape[0]
                vid = VideoWriter(outvid, fourcc, float(fps), size, is_color)
            if size[0] != img.shape[1] and size[1] != img.shape[0]:
                img = resize(img, size)
            vid.write(img)
        vid.release()
        return vid

        # Un radio de 4 pixeles es equivalente a un radio de 0.0002 en wcs
home_security.py 文件源码 项目:home-security 作者: icode-co-il 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def main():
    cap = cv2.VideoCapture(0)
    frame_size = (int(cap.get(3)), int(cap.get(4)))
    fourcc = cv2.cv.CV_FOURCC(*"XVID")

    prev_frame = None
    last_motion = None
    motion_filename = None
    motion_file = None

    while cap.isOpened():
        now = datetime.datetime.now()
        success, frame = cap.read()
        assert success, "failed reading frame"

        frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        frame_gray = cv2.GaussianBlur(frame_gray, (21, 21), 0)

        if have_motion(prev_frame, frame_gray):
            if motion_file is None:
                motion_filename = now.strftime("%Y_%m_%d_%H_%M_%S_MOTION.avi")
                motion_file = cv2.VideoWriter(motion_filename, fourcc, 20.0, frame_size)
            last_motion = now
            print "Motion!", last_motion

        if motion_file is not None:
            motion_file.write(frame)
            if now - last_motion > MOTION_RECORD_TIME:
                motion_file.release()
                motion_file = None
                Process(target = push_file, args = (motion_filename, )).start()

        prev_frame = frame_gray
        cv2.imshow('frame', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()
managers.py 文件源码 项目:Cameo 作者: veraposeidon 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _writevideoframe(self):
        if not self.is_writingvideo:
            return
        if self._videoWriter is None:
            fps = self._capture.get(cv2.CAP_PROP_FPS)
            if fps == 0.0:
                # FPS???????
                if self._frameElapsed < 20:
                    # wait until more frame elapse so that the estimate is more stable.
                    return
                else:
                    fps = self._fpsEstimate
                    # print fps
            size = (int(self._capture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(self._capture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
            self._videoWriter = cv2.VideoWriter(self._videoFilename, self._videoEncoding, fps, size)

        self._videoWriter.write(self._frame)
recordedCamera.py 文件源码 项目:2016-Tegra-OpenCV 作者: HighlandersFRC 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def start(self):
        now = dt.datetime.now()
        if len(self.path) !=0 and self.path[len(self.path)-1] != '/':
            self.path = self.path + '/'    
        output_name = self.path + str(dt.datetime.date(now))+ '-0.avi'
        video_num = 1
        while os.path.isfile(output_name):
            output_name = self.path +str(dt.datetime.date(now)) + '-'+str(video_num)+'.avi'
            video_num = video_num + 1
        fourcc = cv2.cv.CV_FOURCC(*'XVID')
        self.out = cv2.VideoWriter(output_name,fourcc,self.framerate,(self.width,self.height)) 
        return self


问题


面经


文章

微信
公众号

扫码关注公众号