Пример #1
0
    def __init__(self):
        print("[INFO] Loading model...")
        global yolo
        yolo = Load_Yolo_model()

        print("[INFO] Loading modules...")
        self.bridge = CvBridge()
        classNum = len(list(read_class_names(YOLO_COCO_CLASSES).values()))
        self.ClassNames = read_class_names(YOLO_COCO_CLASSES)
        self.OH = Object_handler(classNum)

        print("[INFO] Loading videofeed...")
        self.image_sub_depth = rospy.Subscriber(
            "/zed2/zed_node/depth/depth_registered", Image,
            self.callback_depth)
        self.image_sub_camera = rospy.Subscriber(
            "/zed2/zed_node/left/image_rect_color", Image, self.callback_cam)

        print("[INFO] initializing config...")
        self.show = 1
        self.dep_active = 0
        self.cal_active = 0
        self.min_depth = 0.3

        #self.Update_Images()
        print("[INFO] Loading complete")
Пример #2
0
    def __init__(self):
        print("[INFO] Loading model...")
        #global yolo
        self.yolo = Load_Yolo_model()

        print("[INFO] Loading modules...")
        self.bridge = CvBridge()
        classNum = len(list(read_class_names(YOLO_COCO_CLASSES).values()))
        self.ClassNames = read_class_names(YOLO_COCO_CLASSES)
        self.OH = Object_handler(classNum)

        print("[INFO] Loading videofeed...")
        image_sub = message_filters.Subscriber(
            "/zed2/zed_node/left/image_rect_color", Image)
        cloud_sub = message_filters.Subscriber(
            "/zed2/zed_node/point_cloud/cloud_registered", PointCloud2)
        self.pose_pub = rospy.Publisher('/Published_pose',
                                        PoseStamped,
                                        queue_size=1)
        self.reduc_cloud_pub = rospy.Publisher("/Reduced_cloud",
                                               PointCloud2,
                                               queue_size=1)

        print("[INFO] initializing config...")
        self.show = False  # Show tracker
        self.seg_plot = False  # Create segmentation plot

        print("[INFO] Initialize Display...")
        Frank = cv2.imread(
            os.path.join(os.path.dirname(__file__), "Frank/Frank.png"),
            cv2.IMREAD_COLOR)

        print("[INFO] Loading complete")
        mf = message_filters.TimeSynchronizer([image_sub, cloud_sub], 1)
        mf.registerCallback(self.callback)
Пример #3
0
    def __init__(self):
        self.no_decbbox = 0
        print("[INFO] Initializing ROS...")
        rospy.init_node('Detection')

        print("[INFO] Loading modules...")
        self.yolo = Load_Yolo_model()
        self.bridge = CvBridge()

        print("[INFO] Loading config...")
        # Create local variables
        self.timer = TimeReference()

        print("[INFO] Initialize ROS publishers...")
        # Create Topics to publish
        self.boxes_pub = rospy.Publisher("/Tracker/Detection/Boxes",
                                         Detection2DArray,
                                         queue_size=1)
        self.timer_pub = rospy.Publisher("/Tracker/Timer",
                                         TimeReference,
                                         queue_size=1)

        print("[INFO] Initialize ROS Subscribers...")
        rospy.Subscriber("/zed2/zed_node/left/image_rect_color/compressed",
                         CompressedImage,
                         self.callback,
                         queue_size=400)
        # Create subscriptions

        print("[INFO] Loading complete")
Пример #4
0
def detection(request):

    # base64이미지를 jpg로 저장
    im = get_image_from_data_url(request.data['image'])

    image = Images()
    image.images = im
    image.save()

    image = Images.objects.last()
    image.images = im
    image.save()

    # 비교할 정답
    answer = request.data['question']

    # YOLO사용 준비
    os.environ['CUDA_VISIBLE_DEVICES'] = '0'
    video_path = ""

    # YOLO 모델로 detecting
    last_image = Images.objects.last().images
    yolo = Load_Yolo_model()
    is_correct, info = detect_image(yolo,
                                    image.images.url,
                                    answer,
                                    input_size=YOLO_INPUT_SIZE,
                                    show=True,
                                    rectangle_colors=(255, 0, 0))

    return Response({
        'message': '사진 테스트 완료!!',
        'is_correct': is_correct,
        'info': info
    })
Пример #5
0
def predict():
    if request.method == 'POST':

        # Read File and file data
        im_data = request.get_data()

        with open("capture.jpg", "wb") as im:
            im.write(base64.decodebytes(im_data))

        # image_path = file_path
        image_path = 'capture.jpg'

        # Model expects a 4 dimensional Tensor that has the layout: [Batch index,Width,Height,Channel]
        # Make prediction
        yolo = Load_Yolo_model()
        image, score, label = detect_image(yolo,
                                           image_path,
                                           "detect.jpg",
                                           input_size=YOLO_INPUT_SIZE,
                                           show=True,
                                           CLASSES=TRAIN_CLASSES,
                                           rectangle_colors=(255, 0, 0))
        label = str(label)
        score = str(score)
        result = str([score, label])
        return result

        # detect_predict(data)

        # return get_detected_object

    return None
Пример #6
0
    def __init__(self):
        print("[INFO] Initializing ROS...")
        rospy.init_node('Detection')

        print("[INFO] Loading modules...")
        self.yolo = Load_Yolo_model()
        self.bridge = CvBridge()

        print("[INFO] Loading config...")
        self.timer = TimeReference()

        print("[INFO] Initialize ROS publishers...")
        self.boxes_pub = rospy.Publisher("/Tracker/Detection/Boxes",
                                         Detection2DArray,
                                         queue_size=1)
        self.timer_pub = rospy.Publisher("/Tracker/Timer",
                                         TimeReference,
                                         queue_size=1)

        print("[INFO] Initialize ROS Subscribers...")
        rospy.Subscriber("/zed2/zed_node/left/image_rect_color/compressed",
                         CompressedImage,
                         self.callback_sub,
                         queue_size=1)

        print("[INFO] Loading complete")
        self.init_time_delay = 0
        self.callback()
Пример #7
0
    def __init__(self, detect_classes=None):
        '''
		YOLOv3 TF2 module class for vehicle inference, training, crop. Supports object both normal and tiny implementations.
		TO DO: 1.add tiny and normal implementations
				2. add choice of detect_classes
		'''
        detect_classes = detect_classes
        VehicleDetector.yolo_obj = Load_Yolo_model()
Пример #8
0
class YoloClass():
    yolo = Load_Yolo_model()

    def load_cnn_data(self, double_check_list):
        w, h = 128, 128
        x = []

        for fp in double_check_list:

            img = cv2.resize(fp, (w, h), interpolation=cv2.INTER_AREA)
            img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
            x.append(img_rgb)
            x_arr = np.asarray(x).astype('float32')
            x_arr = x_arr / 255
            x_arr = x_arr.reshape(x_arr.shape[0], w, h, 3)
        return x_arr

    _name = ["牛肉", "水煮蛋", "花椰菜", "高麗菜", "雞肉", "鯖魚", "番薯", "鮭魚", "番茄"]

    def food_name(self, food):
        return [self._name[i] for i in food]

    def aiPredict(self, image_path):
        # block_image_path = "./block"
        # image_path   = "./test10.jpg"
        # video_path   = "./IMAGES/test2.mp4"

        image = cv2.imread(image_path)
        _, cord = detect_image(self.yolo,
                               image_path,
                               output_path="./answer.jpg",
                               input_size=YOLO_INPUT_SIZE,
                               show=False,
                               CLASSES=TRAIN_CLASSES,
                               rectangle_colors=(255, 0, 0))

        double_check_list = []
        for i, block in enumerate(cord):
            x1 = block[0][0]
            x2 = block[1][0]
            y1 = block[0][1]
            y2 = block[1][1]
            crop_img = image[y1:y2, x1:x2]
            double_check_list.append(crop_img)
            #cv2.imwrite(f"./block/block_{i}.jpg", crop_img)

        x_test = self.load_cnn_data(double_check_list)
        reload_model = tf.keras.models.load_model(
            './cnn_model/resNet_model3_w128_h128.h5')

        predict_class = reload_model.predict(x_test)
        predict_class = np.argmax(predict_class, axis=1)

        ret = self.food_name(predict_class)
        # print(ret)
        return ret
Пример #9
0
    def __init__(self):
        global yolo
        self.image_pub = rospy.Publisher("image_topic_2", Image, queue_size=1)

        self.bridge = CvBridge()
        #self.image_sub = rospy.Subscriber("/usb_cam/image_raw",Image,self.callback)
        self.image_sub = rospy.Subscriber(
            "/zed2/zed_node/left/image_rect_color", Image,
            self.callback)  #, queue_size=1,buff_size=2**24)
        #self.image_sub = rospy.Subscriber("/zed2/zed_node/left/image_rect_color/compressed",CompressedImage,self.callback)#, queue_size=1,buff_size=2**8)
        yolo = Load_Yolo_model()
Пример #10
0
 def __init__(self):
   global yolo
   self.show=1 # 0: don't show 1: show
   self.active=1#0
   self.cv_image_cam=[]
   self.cv_image_depth=[]
   self.image_pub = rospy.Publisher("image_topic_2",Image)
   self.bridge = CvBridge()
   self.image_sub_camera = rospy.Subscriber("/zed2/zed_node/left/image_rect_color",Image,self.callback_cam)
   self.image_sub = rospy.Subscriber("/zed2/zed_node/depth/depth_registered",Image,self.callback_depth)
   yolo = Load_Yolo_model()
Пример #11
0
    def __init__(self):
        print("[INFO] Loading model...")
        #global yolo
        self.yolo = Load_Yolo_model()

        print("[INFO] Loading modules...")
        self.bridge = CvBridge()
        classNum = len(list(read_class_names(YOLO_COCO_CLASSES).values()))
        self.ClassNames = read_class_names(YOLO_COCO_CLASSES)
        self.OH = Object_handler(classNum)

        print("[INFO] Loading videofeed...")
        image_sub = message_filters.Subscriber(
            "/zed2/zed_node/left/image_rect_color", Image)
        cloud_sub = message_filters.Subscriber(
            "/zed2/zed_node/point_cloud/cloud_registered", PointCloud2)
        #Odometry_sub = message_filters.Subscriber('/odometry/filtered_map', Odometry)
        #self.vehicle_pose = rospy.Subscriber('/odometry/filtered_map', Odometry, self.callback_odom)
        self.pose_pub = rospy.Publisher('/Published_pose',
                                        PoseStamped,
                                        queue_size=1)
        self.reduc_cloud_pub = rospy.Publisher("/Reduced_cloud",
                                               PointCloud2,
                                               queue_size=1)
        #self.seg_plot_pub = rospy.Publisher("/seg_img",Image,queue_size=1)

        self.timed_cloud_pub = rospy.Publisher("/Timed_cloud",
                                               PointCloud2,
                                               queue_size=1)
        self.boxed_image_pub = rospy.Publisher("/Boxed_image",
                                               Image,
                                               queue_size=1)

        print("[INFO] initializing config...")
        self.Target_class = 0  # Class 0 is person
        self.Target_Found = False
        self.Target_UID = []
        self.show = True  # Show tracker
        self.seg_plot = True  # Create segmentation plot

        print("[INFO] Initialize Display...")
        Frank = cv2.imread(
            os.path.join(os.path.dirname(__file__), "Frank/Frank.png"),
            cv2.IMREAD_COLOR)

        print("[INFO] Loading complete")
        #mf = message_filters.ApproximateTimeSynchronizer([image_sub,depth_sub,cloud_sub],1,0.07)
        #mf = message_filters.ApproximateTimeSynchronizer([image_sub,cloud_sub],1,5) #Set close to zero in order to syncronize img and point cloud (be aware of frame rate)
        mf = message_filters.TimeSynchronizer([image_sub, cloud_sub], 10)
        mf.registerCallback(self.callback)
Пример #12
0
	def __init__(self):
		print("[INFO] Loading model...")
		global yolo
		yolo = Load_Yolo_model()
		

		print("[INFO] Loading modules...")
		self.bridge = CvBridge()
		classNum = len(list(read_class_names(YOLO_COCO_CLASSES).values()))
		self.ClassNames = read_class_names(YOLO_COCO_CLASSES)
		self.OH 	= Object_handler(classNum)

		print("[INFO] Loading videofeed...")
		self.image_sub = rospy.Subscriber("/usb_cam/image_raw",Image,self.callback)

		print("[INFO] Loading complete")
Пример #13
0
    def __init__(self):
        self.yolo = Load_Yolo_model()
        self.bridge = CvBridge()

        self.bbox_pub = rospy.Publisher("/yolo/bboxes",
                                        Detection2DArray,
                                        queue_size=1)
        self.time_pub = rospy.Publisher("/yolo/Time",
                                        CompressedImage,
                                        queue_size=1)

        time_sub = rospy.Subscriber(
            "/zed2/zed_node/left/image_rect_color/compressed", CompressedImage,
            self.callback_images)
        some_sub = rospy.Subscriber("/yolo/Time", CompressedImage,
                                    self.callback_yolo)
Пример #14
0
    def __init__(self):
        self.yolo = Load_Yolo_model()
        self.bridge = CvBridge()

        self.bbox_pub = rospy.Publisher("/yolo/bboxes",
                                        Detection2DArray,
                                        queue_size=1)
        self.time_pub = rospy.Publisher("/yolo/Timer",
                                        Image,
                                        queue_size=1,
                                        tcp_nodelay=True)

        rospy.Subscriber("/zed2/zed_node/left/image_rect_color", Image,
                         self.callback_images)
        rospy.Subscriber("/yolo/Time",
                         Image,
                         self.callback_yolo,
                         tcp_nodelay=True)
    def __init__(self):
        print("[INFO] Loading model...")
        #global yolo
        self.yolo = Load_Yolo_model()

        print("[INFO] Loading modules...")
        self.bridge = CvBridge()
        classNum = len(list(read_class_names(YOLO_COCO_CLASSES).values()))
        self.ClassNames = read_class_names(YOLO_COCO_CLASSES)
        self.OH = Object_handler(classNum)

        print("[INFO] Loading videofeed...")
        image_sub = message_filters.Subscriber(
            "/zed2/zed_node/left/image_rect_color", Image)
        #depth_sub = message_filters.Subscriber("/zed2/zed_node/depth/depth_registered",Image)
        cloud_sub = message_filters.Subscriber(
            "/zed2/zed_node/point_cloud/cloud_registered", PointCloud2)

        print("[INFO] initializing config...")
        #self.show=1
        self.seg_plot = True
        #self.dep_active = 0
        #self.cal_active = 0
        #self.min_depth = 0.3

        print("[INFO] Initialize Display...")

        Frank = cv2.imread(
            os.path.join(os.path.dirname(__file__), "Frank/Frank.png"),
            cv2.IMREAD_COLOR)
        #cv2.imshow("Image_window",Frank)
        #detect_image(yolo, Frank, "", input_size=YOLO_INPUT_SIZE, show=False, rectangle_colors=(255,0,0))
        #self.Update_Images()
        print("[INFO] Loading complete")
        #mf = message_filters.ApproximateTimeSynchronizer([image_sub,depth_sub,cloud_sub],1,0.07)
        #mf = message_filters.ApproximateTimeSynchronizer([image_sub,cloud_sub],1,0.07)
        mf = message_filters.TimeSynchronizer([image_sub, cloud_sub], 1)
        mf.registerCallback(self.callback)
Пример #16
0
    def __init__(self):
        print("[INFO] Loading model...")
        global yolo
        yolo = Load_Yolo_model()

        print("[INFO] Loading modules...")
        self.bridge = CvBridge()
        classNum = len(list(read_class_names(YOLO_COCO_CLASSES).values()))
        self.ClassNames = read_class_names(YOLO_COCO_CLASSES)
        self.OH = Object_handler(classNum)

        print("[INFO] Loading videofeed...")
        image_sub = message_filters.Subscriber(
            "/zed2/zed_node/left/image_rect_color", Image)
        cloud_sub = message_filters.Subscriber(
            "/zed2/zed_node/point_cloud/cloud_registered", PointCloud2)
        mf = message_filters.ApproximateTimeSynchronizer(
            [image_sub, cloud_sub], 1, 10)
        mf.registerCallback(self.callback)

        print("INFO Initialize display")

        print("[INFO] Loading complete")
Пример #17
0
# ================================================================
#
#   File name   : detection_custom.py
#   Description : Performs object detection for images
#
#================================================================
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import cv2
import numpy as np
import tensorflow as tf
from yolov3.utils import detect_image, detect_realtime, detect_video, Load_Yolo_model, detect_video_realtime_mp
from yolov3.configs import *


image_path = "/home/014505660/fl_project/kitti_dataset/testing/image_2/000010.png"

yolo = Load_Yolo_model()
detect_image(yolo, image_path, "./IMAGES/test_1_detect.jpg", input_size=YOLO_INPUT_SIZE, show=False, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0))
Пример #18
0
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import cv2
import numpy as np
import tensorflow as tf
import tensorflowjs as tfjs
from yolov3.utils import detect_image, detect_realtime, detect_video, Load_Yolo_model, detect_video_realtime_mp
from yolov3.configs import *



yolo = Load_Yolo_model()
yolo.summary()
# yolo.save('mymodel.h5')
# filepath = 'tfjs-models2'
# filepath = 'tfjs-models4'
# tf.keras.models.save_model(
#     yolo, filepath, overwrite=True, include_optimizer=True, save_format=None,
#     signatures=None, options=None
# )

# tf.saved_model.save(yolo, 'tfjs-models3')
# tfjs.converters.save_keras_model(yolo, 'tfjs-models')