当前位置: 首页>>代码示例>>Python>>正文


Python cv2.FONT_HERSHEY_COMPLEX属性代码示例

本文整理汇总了Python中cv2.FONT_HERSHEY_COMPLEX属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.FONT_HERSHEY_COMPLEX属性的具体用法?Python cv2.FONT_HERSHEY_COMPLEX怎么用?Python cv2.FONT_HERSHEY_COMPLEX使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cv2的用法示例。


在下文中一共展示了cv2.FONT_HERSHEY_COMPLEX属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: drawBoundingBox

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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 
开发者ID:AmeyaWagh,项目名称:Traffic_sign_detection_YOLO,代码行数:22,代码来源:objectDetectorYOLO.py

示例2: drawBoundingBox

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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 
开发者ID:AmeyaWagh,项目名称:Traffic_sign_detection_YOLO,代码行数:25,代码来源:YOLOtest.py

示例3: imshow

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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) 
开发者ID:MagicChuyi,项目名称:SlowFast-Network-pytorch,代码行数:27,代码来源:video_demo.py

示例4: show_net_input

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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) 
开发者ID:MagicChuyi,项目名称:SlowFast-Network-pytorch,代码行数:25,代码来源:AVA_video_v2.py

示例5: draw_debug_frame_for_object

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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 
开发者ID:gaborvecsei,项目名称:Color-Tracker,代码行数:21,代码来源:visualize.py

示例6: get_legends

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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 
开发者ID:divamgupta,项目名称:image-segmentation-keras,代码行数:19,代码来源:predict.py

示例7: run_app

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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) 
开发者ID:becauseofAI,项目名称:MobileFace,代码行数:19,代码来源:mobileface_detector_app.py

示例8: visualize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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 
开发者ID:haixpham,项目名称:end2end_AU_speech,代码行数:25,代码来源:ShapeUtils2.py

示例9: test_detector

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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() 
开发者ID:TuXiaokang,项目名称:pyseeta,代码行数:20,代码来源:test_opencv.py

示例10: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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 
开发者ID:opencv,项目名称:open_model_zoo,代码行数:19,代码来源:image_inpainting_demo.py

示例11: draw_all_detection

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
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 
开发者ID:deepinsight,项目名称:insightface,代码行数:30,代码来源:tester.py

示例12: draw_poly_detections

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
def draw_poly_detections(img, detections, class_names, scale, threshold=0.2):
    """

    :param img:
    :param detections:
    :param class_names:
    :param scale:
    :param cfg:
    :param threshold:
    :return:
    """
    import pdb
    import cv2
    import random
    assert isinstance(class_names, (tuple, list))
    img = mmcv.imread(img)
    color_white = (255, 255, 255)

    for j, name in enumerate(class_names):
        color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256))
        try:
            dets = detections[j]
        except:
            pdb.set_trace()
        for det in dets:
            bbox = det[:8] * scale
            score = det[-1]
            if score < threshold:
                continue
            bbox = list(map(int, bbox))

            cv2.circle(img, (bbox[0], bbox[1]), 3, (0, 0, 255), -1)
            for i in range(3):
                cv2.line(img, (bbox[i * 2], bbox[i * 2 + 1]), (bbox[(i+1) * 2], bbox[(i+1) * 2 + 1]), color=color, thickness=2)
            cv2.line(img, (bbox[6], bbox[7]), (bbox[0], bbox[1]), color=color, thickness=2)
            cv2.putText(img, '%s %.3f' % (class_names[j], score), (bbox[0], bbox[1] + 10),
                        color=color_white, fontFace=cv2.FONT_HERSHEY_COMPLEX, fontScale=0.5)
    return img 
开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:40,代码来源:inference.py

示例13: draw_bboxes_and_show

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
def draw_bboxes_and_show(self,frame,frame_num,bboxes,labels,key_frame_start,key_frame_end,scale=1,probs=[],color=(255, 255, 255)):

            if frame_num > key_frame_start and frame_num < key_frame_end:
                count = 0
                count_2=0
                # Capture frame-by-frame
                if len(probs)==0:
                    for bbox, lable in zip(bboxes, labels):
                        count = count + 1
                        bbox = np.array(bbox)
                        lable = int(lable)
                        real_x_min = int(bbox[0] / scale)
                        real_y_min = int(bbox[1] / scale)
                        real_x_max = int(bbox[2] / scale)
                        real_y_max = int(bbox[3] / scale)
                        # 在每一帧上画矩形,frame帧,(四个坐标参数),(颜色),宽度
                        cv2.rectangle(frame, (real_x_min, real_y_min), (real_x_max, real_y_max), color, 4)
                        cv2.putText(frame, self.i2c_dic[str(lable)], (real_x_min + 30, real_y_min + 15 * count),
                                    cv2.FONT_HERSHEY_COMPLEX, \
                                    0.5, (255, 255, 0), 1, False)
                else:
                    for bbox,lable,prob in zip(bboxes,labels,probs):
                        count_2 = count_2 + 1
                        bbox=np.array(bbox)
                        lable = int(lable)
                        prob=float(prob)
                        print("probs",probs)
                        real_x_min = int(bbox[0]/scale)
                        real_y_min = int(bbox[1]/scale)
                        real_x_max = int(bbox[2]/scale)
                        real_y_max = int(bbox[3]/scale)
                        # 在每一帧上画矩形,frame帧,(四个坐标参数),(颜色),宽度
                        cv2.rectangle(frame, (real_x_min, real_y_min), (real_x_max, real_y_max), (255, 255, 255), 4)
                        cv2.putText(frame, self.i2c_dic[str(lable)]+':'+str(prob), (real_x_min+30 , real_y_min+15*count_2 ), cv2.FONT_HERSHEY_COMPLEX,\
                        0.5,(255, 255, 0), 1, False) 
开发者ID:MagicChuyi,项目名称:SlowFast-Network-pytorch,代码行数:37,代码来源:AVA_video_v1.py

示例14: test

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
def test(self,item_num):
        i2c_dic=self.index2class()
        for i in range(item_num):
            result=self.__getitem__(i)
            bboxes=result[3]
            labels=result[4]
            scale=result[2]
            print('scale:',scale)
            print ('bboxes:',bboxes)
            print ('labels:',labels)
            print('dir:',self.path_to_keyframe + '/' + result[0] + ".jpg")
            image = cv2.imread(self.path_to_keyframe + '/' + result[0] + ".jpg")
            count=0
            for bbox,lable in zip(bboxes,labels):
                count=count+1
                bbox=np.array(bbox)
                lable = int(lable)
                real_x_min = int(bbox[0]/scale)
                real_y_min = int(bbox[1]/scale)
                real_x_max = int(bbox[2]/scale)
                real_y_max = int(bbox[3]/scale)
                # 在每一帧上画矩形,frame帧,(四个坐标参数),(颜色),宽度
                cv2.rectangle(image, (real_x_min, real_y_min), (real_x_max, real_y_max), (255, 255, 255), 4)
                cv2.putText(image, i2c_dic[str(lable+1)], (real_x_min + 30, real_y_min + 30 * count), cv2.FONT_HERSHEY_COMPLEX,\
                1,(255, 255, 0), 1, False)
            cv2.imshow('Frame', image)
            # 刷新视频
            cv2.waitKey() 
开发者ID:MagicChuyi,项目名称:SlowFast-Network-pytorch,代码行数:30,代码来源:AVA.py

示例15: draw_bboxes_and_show

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_COMPLEX [as 别名]
def draw_bboxes_and_show(self,frame,frame_num,bboxes,labels,key_frame_start,key_frame_end,scale=1,probs=[]):

            if frame_num > key_frame_start and frame_num < key_frame_end:
                count = 0
                count_2=0
                # Capture frame-by-frame
                if len(probs)==0:#标签
                    for bbox, lable in zip(bboxes, labels):
                        count = count + 1
                        bbox = np.array(bbox)
                        lable = int(lable)
                        real_x_min = int(bbox[0] / scale)
                        real_y_min = int(bbox[1] / scale)
                        real_x_max = int(bbox[2] / scale)
                        real_y_max = int(bbox[3] / scale)
                        # 在每一帧上画矩形,frame帧,(四个坐标参数),(颜色),宽度

                        cv2.rectangle(frame, (real_x_min, real_y_min), (real_x_max, real_y_max),(17,238,105), 4)#绿色
                        cv2.putText(frame, self.i2c_dic[str(lable)], (real_x_min + 15, real_y_min + 15 * count),
                                    cv2.FONT_HERSHEY_COMPLEX, \
                                    0.5, (17,238,105), 1, False)

                else:#预测
                    for bbox,lable,prob in zip(bboxes,labels,probs):
                        count_2 = count_2 + 1
                        bbox=np.array(bbox)
                        lable = int(lable)
                        prob=float(prob)
                        print("probs",probs)
                        real_x_min = int(bbox[0]/scale)
                        real_y_min = int(bbox[1]/scale)
                        real_x_max = int(bbox[2]/scale)
                        real_y_max = int(bbox[3]/scale)
                        # 在每一帧上画矩形,frame帧,(四个坐标参数),(颜色),宽度
                        cv2.rectangle(frame, (real_x_min, real_y_min), (real_x_max, real_y_max), (255, 0, 0),
                                      4)  # 红色
                        cv2.putText(frame, self.i2c_dic[str(lable)]+':'+str(round(prob,2)), (real_x_max - 50, real_y_min + 15 * count),
                                    cv2.FONT_HERSHEY_COMPLEX, \
                                    0.5, (255, 0, 0), 1, False) 
开发者ID:MagicChuyi,项目名称:SlowFast-Network-pytorch,代码行数:41,代码来源:AVA_video_v2.py


注:本文中的cv2.FONT_HERSHEY_COMPLEX属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。