Code Monkey home page Code Monkey logo

Comments (2)

lujian9328 avatar lujian9328 commented on August 16, 2024

@anjanakumar
Yes, you can see the following example method I provided. The key point is applying opencv VideoCapture to read a video and VideoWriter to save your output result. Modified the code in demo.py. One thing to mention is FLAGS.data_file is the video file path and FLAGS.save_video is a bool value to determine whether save the output video.

def run_my_eval(load_out, output_folder, data_file):
    meta_hypes, subhypes, submodules, decoded_logits, sess, image_pl = load_out
    seg_softmax = decoded_logits['segmentation']['softmax']
    pred_boxes_new = decoded_logits['detection']['pred_boxes_new']
    pred_confidences = decoded_logits['detection']['pred_confidences']
    eval_list = [seg_softmax, pred_boxes_new, pred_confidences]

    def my_preprocess(image):
        # define your own method
        pass

    def my_postprocess(shape, image):
        # define your own method
        pass

    assert os.path.isfile(data_file), \
    'file {} does not exist'.format(data_file)

    camera = cv2.VideoCapture(data_file)

    assert camera.isOpened(), \
    'Cannot capture source'

    _, frame = camera.read()
    height, width, _ = frame.shape

    if FLAGS.save_video:
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
        fps = round(camera.get(cv2.CAP_PROP_FPS))
        video_writer = cv2.VideoWriter('video.avi', fourcc, fps, (width, height))

    test_constant_input(subhypes)
    test_segmentation_input(subhypes)

    import utils.train_utils as dec_utils

    # buffers for demo in batch
    buffer_pre = list()

    elapsed = int()
    start = timer()    

    logging.info('Start video prediction.')
    while camera.isOpened():
        elapsed += 1
        _, frame = camera.read()
        if frame is None:
            logging.info('End of Video')
            break

        # resize input frame
        preprocessed = my_preprocess(frame)

        # run one frame predict
        feed_dict = {image_pl: preprocessed}
        output = sess.run(eval_list, feed_dict=feed_dict)

        seg_softmax, pred_boxes_new, pred_confidences = output

        # Create Segmentation Overlay
        shape = preprocessed.shape
        seg_softmax = seg_softmax[:, 1].reshape(shape[0], shape[1])
        hard = seg_softmax > 0.5
        overlay_image = utils.fast_overlay(preprocessed, hard)

        # Draw Detection Boxes
        new_img, rects = dec_utils.add_rectangles(
            subhypes['detection'], [overlay_image], pred_confidences,
            pred_boxes_new, show_removed=False,
            use_stitching=True, rnn_len=subhypes['detection']['rnn_len'],
            min_conf=0.50, tau=subhypes['detection']['tau'])

        postprocessed = my_postprocess(new_img)

        # save one frame in ouput video
        video_writer.write(postprocessed)

        if elapsed % 50 == 0:
            logging.info('Speed (fps): {0:3.3f} FPS'.format(
                elapsed / (timer() - start)))

    logging.info('Video prediction complete. Cost {0:3.3f} sec.'.format(
        timer() - start))
    logging.info('Save output video file to video.avi')
    if FLAGS.save_video:
        video_writer.release()
    camera.release()

from multinet.

screamdw avatar screamdw commented on August 16, 2024

@lujian9328
你好,请问你视频检测成功了吗,这两个函数具体写什么呢【my_preprocess(image),my_postprocess(shape, image)】,看到请回复,谢谢

from multinet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.