Python cv2.FONT_HERSHEY_COMPLEX Examples
The following are 30
code examples of cv2.FONT_HERSHEY_COMPLEX().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: objectDetectorYOLO.py From Traffic_sign_detection_YOLO with MIT License | 11 votes |
def drawBoundingBox(self,imgcv,result): for box in result: # print(box) x1,y1,x2,y2 = (box['topleft']['x'],box['topleft']['y'],box['bottomright']['x'],box['bottomright']['y']) conf = box['confidence'] # print(conf) label = box['label'] if conf < self.predictThresh: continue # print(x1,y1,x2,y2,conf,label) cv2.rectangle(imgcv,(x1,y1),(x2,y2),(0,255,0),6) labelSize=cv2.getTextSize(label,cv2.FONT_HERSHEY_COMPLEX,0.5,2) # print('labelSize>>',labelSize) _x1 = x1 _y1 = y1#+int(labelSize[0][1]/2) _x2 = _x1+labelSize[0][0] _y2 = y1-int(labelSize[0][1]) cv2.rectangle(imgcv,(_x1,_y1),(_x2,_y2),(0,255,0),cv2.FILLED) cv2.putText(imgcv,label,(x1,y1),cv2.FONT_HERSHEY_COMPLEX,0.5,(0,0,0),1) return imgcv
Example #2
Source File: YOLOtest.py From Traffic_sign_detection_YOLO with MIT License | 6 votes |
def drawBoundingBox(self,imgcv,result): #finding max val self.predictThresh=max([box['confidence'] for box in result]) for box in result: # print(box) x1,y1,x2,y2 = (box['topleft']['x'],box['topleft']['y'],box['bottomright']['x'],box['bottomright']['y']) conf = box['confidence'] # print(conf) label = box['label'] print("label",label,"confidence",conf) if conf < self.predictThresh: continue # print(x1,y1,x2,y2,conf,label) cv2.rectangle(imgcv,(x1,y1),(x2,y2),(0,255,0),6) labelSize=cv2.getTextSize(label,cv2.FONT_HERSHEY_COMPLEX,0.5,2) # print('labelSize>>',labelSize) _x1 = x1 _y1 = y1#+int(labelSize[0][1]/2) _x2 = _x1+labelSize[0][0] _y2 = y1-int(labelSize[0][1]) cv2.rectangle(imgcv,(_x1,_y1),(_x2,_y2),(0,255,0),cv2.FILLED) cv2.putText(imgcv,label,(x1,y1),cv2.FONT_HERSHEY_COMPLEX,0.5,(0,0,0),1) return imgcv
Example #3
Source File: mobileface_detector_app.py From MobileFace with MIT License | 6 votes |
def run_app(): args = parse_args() mfdet = MobileFaceDetection(args.model, args.gpus) image_list = [x.strip() for x in args.images.split(',') if x.strip()] for img_dir in image_list: img_mat = cv2.imread(img_dir) results = mfdet.mobileface_detector(img_dir, img_mat) if results == None or len(results) < 1: continue for i, result in enumerate(results): xmin, ymin, xmax, ymax, score, classname = result cv2.rectangle(img_mat, (xmin, ymin), (xmax, ymax), (0,255,0), 3) cv2.putText(img_mat, str('%s%0.2f' % (classname, score)), (xmin, ymin - 5), cv2.FONT_HERSHEY_COMPLEX , 0.8, (0,0,255), 2) cv2.imwrite('friends_result.jpg', img_mat) cv2.imshow('result', img_mat) cv2.waitKey(2000)
Example #4
Source File: ShapeUtils2.py From end2end_AU_speech with MIT License | 6 votes |
def visualize(self, image, e_real, e_fake): shape_fake = calc_shape(self.baseshapes, e_fake) shape_real = calc_shape(self.baseshapes, e_real) self.renderer.render(shape_real, self.triangles) img_real = self.renderer.capture_screen() self.renderer.render(shape_fake, self.triangles) img_fake = self.renderer.capture_screen() # result new_img = np.zeros((300,900,3), dtype=np.uint8) if image is not None: new_img[:,0:300,:] = cv2.resize(image, (300,300), interpolation=cv2.INTER_CUBIC) new_img[:,300:600,:] = img_real[52:352,170:470,:] new_img[:,600:900,:] = img_fake[52:352,170:470,:] # error text if self.draw_error: error = np.sum(np.square(e_real-e_fake)) txt = "error: {:.4f}".format(error) cv2.putText(new_img, txt, (10,280), cv2.FONT_HERSHEY_COMPLEX, 1.0, (255, 0, 255), 1) return new_img
Example #5
Source File: predict.py From image-segmentation-keras with MIT License | 6 votes |
def get_legends(class_names, colors=class_colors): n_classes = len(class_names) legend = np.zeros(((len(class_names) * 25) + 25, 125, 3), dtype="uint8") + 255 class_names_colors = enumerate(zip(class_names[:n_classes], colors[:n_classes])) for (i, (class_name, color)) in class_names_colors: color = [int(c) for c in color] cv2.putText(legend, class_name, (5, (i * 25) + 17), cv2.FONT_HERSHEY_COMPLEX, 0.5, (0, 0, 0), 1) cv2.rectangle(legend, (100, (i * 25)), (125, (i * 25) + 25), tuple(color), -1) return legend
Example #6
Source File: visualize.py From Color-Tracker with MIT License | 6 votes |
def draw_debug_frame_for_object(debug_frame, tracked_object: TrackedObject, color: Tuple[int, int, int] = (255, 255, 255)): # contour = tracked_object.last_object_contour bbox = tracked_object.last_bbox points = tracked_object.tracked_points # if contour is not None: # cv2.drawContours(debug_frame, [contour], -1, (0, 255, 0), cv2.FILLED) if bbox is not None: x1, y1, x2, y2 = bbox cv2.rectangle(debug_frame, (x1, y1), (x2, y2), (255, 255, 255), 1) cv2.putText(debug_frame, "Id {0}".format(tracked_object.id), (x1, y1 - 5), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255)) if points is not None and len(points) > 0: draw_tracker_points(points, debug_frame, color) cv2.circle(debug_frame, tuple(points[-1]), 3, (0, 0, 255), -1) return debug_frame
Example #7
Source File: test_opencv.py From pyseeta with MIT License | 6 votes |
def test_detector(): print('test detector:') # load model detector = Detector() detector.set_min_face_size(30) image_color = cv2.imread('data/chloecalmon.png', cv2.IMREAD_COLOR) image_gray = cv2.cvtColor(image_color, cv2.COLOR_BGR2GRAY) faces = detector.detect(image_gray) for i, face in enumerate(faces): print('({0},{1},{2},{3}) score={4}'.format(face.left, face.top, face.right, face.bottom, face.score)) cv2.rectangle(image_color, (face.left, face.top), (face.right, face.bottom), (0,255,0), thickness=2) cv2.putText(image_color, str(i), (face.left, face.bottom),cv2.FONT_HERSHEY_COMPLEX, 1, (0,255,0), thickness=1) cv2.imshow('test', image_color) cv2.waitKey(0) detector.release()
Example #8
Source File: video_demo.py From SlowFast-Network-pytorch with MIT License | 6 votes |
def imshow(bboxes, labels, probs,ids,count): for bbox, lables, prob,i in zip(bboxes, labels, probs,ids): count_2 = 0 for lable, p in zip(lables, prob): count_2 = count_2 + 1 bbox = np.array(bbox) lable = int(lable) p = float(p) real_x_min = int(bbox[0]) real_y_min = int(bbox[1]) real_x_max = int(bbox[2]) real_y_max = int(bbox[3]) # 在每一帧上画矩形,frame帧,(四个坐标参数),(颜色),宽度 cv2.rectangle(frame, (real_x_min, real_y_min), (real_x_max, real_y_max), (0, 0, 255), 4) # 红色 cv2.putText(frame, index2class()[str(lable)].split("(")[0] + ':' + str(round(p, 2)), (real_x_min + 15, real_y_max - 15 * count_2), cv2.FONT_HERSHEY_COMPLEX, \ 0.5, (0, 0, 255), 1, False) cv2.putText(frame, "id:"+str(i), (real_x_min + 10, real_y_min + 20), cv2.FONT_HERSHEY_COMPLEX, \ 0.5, (0, 0, 255), 1, False) cv2.imwrite('/home/aiuser/frames/%d.jpg' % count, frame)
Example #9
Source File: AVA_video_v2.py From SlowFast-Network-pytorch with MIT License | 6 votes |
def show_net_input(self,buffer,detect_bbox,label_bbox,labels,scale): label_bbox=np.array(label_bbox) detect_bbox=np.array(detect_bbox) label_bbox[:,[0, 2]] *= scale[0] label_bbox[:,[1, 3]] *= scale[1] detect_bbox[:,[0, 2]] *= scale[0] detect_bbox[:,[1, 3]] *= scale[1] print("detect_bbox:", np.round(detect_bbox,1)) print("label_bbox:", np.round(label_bbox,1)) print("labels:", labels) for f in buffer: for i,r in enumerate(label_bbox): cv2.rectangle(f, (int(r[0]), int(r[1])), (int(r[2]), int(r[3])), (0, 170, 17), 1) for n, l in enumerate(labels[i]): cv2.putText(f, self.i2c_dic[str(l)], (int(r[0]) + 10, int(r[1]) + 10* n), cv2.FONT_HERSHEY_COMPLEX,0.4,(255, 255, 0), 1, False) for d in detect_bbox: cv2.rectangle(f, (int(d[0]), int(d[1])), (int(d[2]), int(d[3])), (255, 255, 255), 1) cv2.imshow('Frame', f) # 刷新视频 cv2.waitKey(0)
Example #10
Source File: image_inpainting_demo.py From open_model_zoo with Apache License 2.0 | 6 votes |
def main(): args = build_argparser().parse_args() ie = IECore() inpainting_processor = ImageInpainting(ie, args.model, args.parts, args.max_brush_width, args.max_length, args.max_vertex, args.device) img = cv2.imread(args.input, cv2.IMREAD_COLOR) masked_image, output_image = inpainting_processor.process(img) concat_imgs = np.hstack((masked_image, output_image)) cv2.putText(concat_imgs, 'summary: {:.1f} FPS'.format( float(1 / inpainting_processor.infer_time)), (5, 15), cv2.FONT_HERSHEY_COMPLEX, 0.5, (0, 0, 200)) if not args.no_show: cv2.imshow('Image Inpainting Demo', concat_imgs) key = cv2.waitKey(0) if key == 27: return
Example #11
Source File: tester.py From Decoupled-Classification-Refinement with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #12
Source File: tester.py From Decoupled-Classification-Refinement with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #13
Source File: tester.py From Faster_RCNN_for_DOTA with Apache License 2.0 | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #14
Source File: tester.py From Decoupled-Classification-Refinement with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #15
Source File: tester.py From Decoupled-Classification-Refinement with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #16
Source File: tester.py From Deformable-ConvNets with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #17
Source File: object_detection_demo_centernet.py From open_model_zoo with Apache License 2.0 | 5 votes |
def main(): args = build_argparser().parse_args() ie = IECore() detector = Detector(ie, args.model, args.prob_threshold, args.device) img = cv2.imread(args.input[0], cv2.IMREAD_COLOR) frames_reader, delay = (VideoReader(args.input), 1) if img is None else (ImageReader(args.input), 0) if args.labels: with open(args.labels, 'r') as f: labels_map = [x.strip() for x in f] else: labels_map = None for frame in frames_reader: detections = detector.detect(frame) for det in detections: xmin, ymin, xmax, ymax = det[:4].astype(np.int) xmin = max(0, xmin) ymin = max(0, ymin) xmax = min(frame.shape[1], xmax) ymax = min(frame.shape[0], ymax) class_id = det[5] det_label = labels_map[int(class_id)] if labels_map else str(int(class_id)) color = (min(class_id * 12.5, 255), min(class_id * 7, 255), min(class_id * 3, 255)) cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2) cv2.putText(frame, det_label + ' ' + str(round(det[4] * 100, 1)) + ' %', (xmin, ymin - 7), cv2.FONT_HERSHEY_COMPLEX, 0.6, color, 1) cv2.putText(frame, 'summary: {:.1f} FPS'.format( float(1 / (detector.infer_time * len(detections)))), (5, 15), cv2.FONT_HERSHEY_COMPLEX, 0.5, (0, 0, 200)) if args.no_show: continue cv2.imshow('CenterNet Detection Demo', frame) key = cv2.waitKey(delay) if key == 27: return
Example #18
Source File: tester.py From Accel with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #19
Source File: tester.py From Accel with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #20
Source File: show_boxes.py From Accel with MIT License | 5 votes |
def draw_boxes(im, dets, classes, scale = 1.0): color_white = (255, 255, 255) for cls_idx, cls_name in enumerate(classes): cls_dets = dets[cls_idx] for det in cls_dets: bbox = det[:4] * scale bbox = map(int, bbox) color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=3) if cls_dets.shape[1] == 5: score = det[-1] cv2.putText(im, '%s %.3f' % (cls_name, score), (bbox[0], bbox[1]+10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=1, thickness=2) return im
Example #21
Source File: tester.py From Accel with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #22
Source File: close_kitti_loops.py From calc2.0 with Apache License 2.0 | 5 votes |
def update(self, x, y, is_loop, _im, _loop_im = None): x0, y0 = self.world2canvas(self.xs[-1], self.ys[-1]) x1, y1 = self.world2canvas(x, y) cv2.line(self.canvas, (x0,y0), (x1,y1), color=(255,0,0), thickness=7) self.xs.append(x) self.ys.append(y) sc = .4 h,w = (int(sc*_im.shape[0]),int(sc*_im.shape[1])) im = cv2.resize(_im, (w,h)) self.canvas[100:(100+h), :w, :] = im cv2.putText(self.canvas, "Query", (0,50), cv2.FONT_HERSHEY_COMPLEX, 1.0, (255,255,255)) cv2.putText(self.canvas, "Match", (0,150+h), cv2.FONT_HERSHEY_COMPLEX, 1.0, (255,255,255)) if is_loop: r = 7 cv2.circle(self.canvas, (x1,y1), r, color=(0,0,255), thickness=-1) loop_im = cv2.resize(_loop_im, (w,h)) self.match = True self.canvas[(200+h):(200+2*h), :w, :] = loop_im elif self.match == False: loop_im = 30*np.ones((h,w,3),dtype=np.uint8) cv2.putText(loop_im, "No Match", (66,h//2), cv2.FONT_HERSHEY_COMPLEX, 2.0, (255,255,255)) self.canvas[(200+h):(200+2*h), :w, :] = loop_im cv2.imshow("Loops", self.canvas) cv2.waitKey(1)
Example #23
Source File: infer.py From DeepOcrService with MIT License | 5 votes |
def viz_result(img, rois, texts): for i, text in enumerate(texts): x = rois[i][0] y = rois[i][1] cv2.putText(img, text, (x, y), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0)) cv2.namedWindow('result', cv2.WINDOW_NORMAL) cv2.resizeWindow('result', 800, 800) cv2.imshow('result', img) k = cv2.waitKey() if k == 27: # ESC exit(-1)
Example #24
Source File: tester.py From RoITransformer_DOTA with MIT License | 5 votes |
def draw_all_poly_detection(im_array, detections, class_names, scale, cfg, threshold=0.2): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) if DEBUG: class_names = ['__background__', 'fg'] for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:8] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) # draw first point cv2.circle(im, (bbox[0], bbox[1]), 3, (0, 0, 255), -1) for i in range(3): cv2.line(im, (bbox[i * 2], bbox[i * 2 + 1]), (bbox[(i+1) * 2], bbox[(i+1) * 2 + 1]), color=color, thickness=2) cv2.line(im, (bbox[6], bbox[7]), (bbox[0], bbox[1]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #25
Source File: tester.py From RoITransformer_DOTA with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #26
Source File: demo.py From RoITransformer_DOTA with MIT License | 5 votes |
def draw_all_poly_detection(im_array, detections, class_names, scale, cfg, threshold=0.2): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ # pdb.set_trace() import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color try: dets = detections[j] except: pdb.set_trace() for det in dets: bbox = det[:8] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) # draw first point cv2.circle(im, (bbox[0], bbox[1]), 3, (0, 0, 255), -1) for i in range(3): cv2.line(im, (bbox[i * 2], bbox[i * 2 + 1]), (bbox[(i+1) * 2], bbox[(i+1) * 2 + 1]), color=color, thickness=2) cv2.line(im, (bbox[6], bbox[7]), (bbox[0], bbox[1]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #27
Source File: tester.py From RoITransformer_DOTA with MIT License | 5 votes |
def draw_all_poly_detection(im_array, detections, class_names, scale, cfg, threshold=0.2): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) if DEBUG: class_names = ['__background__', 'fg'] for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:8] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) # draw first point cv2.circle(im, (bbox[0], bbox[1]), 3, (0, 0, 255), -1) for i in range(3): cv2.line(im, (bbox[i * 2], bbox[i * 2 + 1]), (bbox[(i+1) * 2], bbox[(i+1) * 2 + 1]), color=color, thickness=2) cv2.line(im, (bbox[6], bbox[7]), (bbox[0], bbox[1]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #28
Source File: tester.py From RoITransformer_DOTA with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #29
Source File: tester.py From Deformable-ConvNets with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale, cfg, threshold=1e-1): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, cfg.network.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] if score < threshold: continue bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im
Example #30
Source File: tester.py From mxnet-SSH with MIT License | 5 votes |
def draw_all_detection(im_array, detections, class_names, scale): """ visualize all detections in one image :param im_array: [b=1 c h w] in rgb :param detections: [ numpy.ndarray([[x1 y1 x2 y2 score]]) for j in classes ] :param class_names: list of names in imdb :param scale: visualize the scaled image :return: """ import cv2 import random color_white = (255, 255, 255) im = image.transform_inverse(im_array, config.PIXEL_MEANS) # change to bgr im = cv2.cvtColor(im, cv2.cv.CV_RGB2BGR) for j, name in enumerate(class_names): if name == '__background__': continue color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) # generate a random color dets = detections[j] for det in dets: bbox = det[:4] * scale score = det[-1] bbox = map(int, bbox) cv2.rectangle(im, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color=color, thickness=2) cv2.putText(im, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10), color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5) return im