def video_demo(args):
    cap = cv2.VideoCapture('data/demo_video.mp4')
    wrapper = Deeplab_Wrapper(new_session(), args.model_name, args.dataset)
    while (cap.isOpened()):
        ret, frame_bgr = cap.read()
        if not ret:
            break
        frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
        img_reshape = wrapper.resize_keeping_aspect_ratio(frame_rgb)

        with Tick('interference'):
            label = wrapper.predict(wrapper.project(img_reshape))
            disp = wrapper.resize_back(voc.get_label_colormap(label[0]))
            overlap = cv2.addWeighted(frame_bgr, 0.5, disp, 0.5, 20)

        cv2.imshow('overlap', overlap)
        if 27 == cv2.waitKey(1):
            break
def images_demo(args):
    wrapper = Deeplab_Wrapper(new_session(), args.model_name, args.dataset)
    voc.show_legend()
    for fn in glob.glob('data/voc/*'):
        img = wrapper.resize_back(wrapper.load_image(fn))
        with Tick('interference'):
            label = wrapper.predict(fn)[0]
        disp = wrapper.resize_back(voc.get_label_colormap(label))
        overlap = cv2.addWeighted(img, 0.5, disp, 0.5, 20)

        fig = plt.figure(figsize=(12, 4),
                         dpi=100,
                         facecolor='w',
                         edgecolor='k')
        sub_plot(fig, 1, 3, 1, 'image', img)
        sub_plot(fig, 1, 3, 2, voc.semantic_report(label), disp)
        sub_plot(fig, 1, 3, 3, 'overlap', overlap)
        plt.show(block=False)
    plt.show()
Esempio n. 3
0
        cv2.waitKey(1)

        if self.output_compressed:
            msg = CompressedImage()
            msg.header = ros_data.header
            msg.format = "jpeg"
            msg.data = np.array(cv2.imencode('.jpg', detections)[1]).tostring()
            self.pub.publish(msg)
        else:
            msg = Image()
            msg.header = ros_data.header
            msg.data = detections.tostring()
            self.pub.publish(msg)


def shutdownFunction(signalnum, frame):
    print('Exit')
    rospy.signal_shutdown(0)


signal.signal(signal.SIGINT, shutdownFunction)
signal.signal(signal.SIGTERM, shutdownFunction)

if __name__ == '__main__':
    assert sys.argv[1] in ['mobilenetv2', 'xception'], sys.argv[1]
    wrapper = Deeplab_Wrapper(new_session(), sys.argv[1])

    input_topic = sys.argv[2]
    output_topic = sys.argv[3]
    node = Deeplab_Node(wrapper, input_topic, output_topic)
    rospy.spin()
Esempio n. 4
0
import time
import cv2
import json
import glob
import numpy as np
import matplotlib.pyplot as plt
import random
import keras
import tensorflow as tf
from tensorflow.python.keras import backend as K

from model_wrapper.utils import voc, sub_plot, Tick, new_session
from deeplab.warpper import Deeplab_Wrapper

sess = new_session()
xception = Deeplab_Wrapper(sess, 'xception')
mobilenet = Deeplab_Wrapper(sess, 'mobilenetv2')
from mask_rcnn.warpper import predict, plot

cap = cv2.VideoCapture('tmp/videos/9_Very_Close_Takeoffs_Landings.mp4')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
font = cv2.FONT_HERSHEY_SIMPLEX
out = cv2.VideoWriter('tmp/deeplab_cmp.avi', fourcc, 30.0, (640 * 2, 360 * 2))
counter, filter1, filter2, filter3 = 0, 0, 0, 0

while (cap.isOpened()):
    with Tick(str(counter)):
        ret, frame_bgr = cap.read()
        frame_bgr = cv2.resize(frame_bgr, (0, 0), fx=0.5, fy=0.5)
        frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
        img_reshape = mobilenet.resize_keeping_aspect_ratio(frame_rgb)
import time
import cv2
import json
import glob
import numpy as np
import matplotlib.pyplot as plt
import random
import keras
import tensorflow as tf
from tensorflow.python.keras import backend as K

from model_wrapper.utils import voc, sub_plot, Tick, new_session
from deeplab.warpper import Deeplab_Wrapper

assert sys.argv[1] in ['mobilenetv2', 'xception'], sys.argv[1]
wrapper = Deeplab_Wrapper(new_session(), sys.argv[1])

cap = cv2.VideoCapture('data/demo_video.mp4')

while (cap.isOpened()):
    ret, frame_bgr = cap.read()
    if not ret:
        break
    frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
    img_reshape = wrapper.resize_keeping_aspect_ratio(frame_rgb)

    with Tick('interference'):
        label = wrapper.predict(wrapper.project(img_reshape))
        disp = wrapper.resize_back(voc.get_label_colormap(label[0]))
        overlap = cv2.addWeighted(frame_bgr, 0.5, disp, 0.5, 20)
Esempio n. 6
0
import time
import cv2
import json
import glob
import numpy as np
import matplotlib.pyplot as plt
import random
import keras
import tensorflow as tf
from tensorflow.python.keras import backend as K

from model_wrapper.utils import voc,sub_plot,Tick,new_session
from deeplab.warpper import Deeplab_Wrapper

assert sys.argv[1] in ['mobilenetv2','xception'], sys.argv[1]
wrapper = Deeplab_Wrapper(new_session(),sys.argv[1])

voc.show_legend()
for fn in glob.glob('data/Pascal_Voc/*'):
    img = wrapper.resize_back(wrapper.load_image(fn))
    with Tick('interference'):
        label = wrapper.predict(fn)[0]
    disp = wrapper.resize_back(voc.get_label_colormap(label))
    overlap = cv2.addWeighted(img, 0.5, disp, 0.5, 20)

    fig = plt.figure(figsize=(12, 4), dpi=100, facecolor='w', edgecolor='k')
    sub_plot(fig,1,3,1,'image',img)
    sub_plot(fig,1,3,2,voc.semantic_report(label),disp)
    sub_plot(fig,1,3,3,'overlap',overlap)
    plt.show(block = False)