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


Python cv2.FONT_HERSHEY_PLAIN属性代码示例

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


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

示例1: vis_det_and_mask

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def vis_det_and_mask(im, class_name, dets, masks, thresh=0.8):
    """Visual debugging of detections."""
    num_dets = np.minimum(10, dets.shape[0])
    colors_mask = random_colors(num_dets)
    colors_bbox = np.round(np.random.rand(num_dets, 3) * 255)
    # sort rois according to the coordinates, draw upper bbox first
    draw_mask = np.zeros(im.shape[:2], dtype=np.uint8)

    for i in range(1):
        bbox = tuple(int(np.round(x)) for x in dets[i, :4])
        mask = masks[i, :, :]
        full_mask = unmold_mask(mask, bbox, im.shape)

        score = dets[i, -1]
        if score > thresh:
            word_width = len(class_name)
            cv2.rectangle(im, bbox[0:2], bbox[2:4], colors_bbox[i], 2)
            cv2.rectangle(im, bbox[0:2], (bbox[0] + 18 + word_width*8, bbox[1]+15), colors_bbox[i], thickness=cv2.FILLED)
            apply_mask(im, full_mask, draw_mask, colors_mask[i], 0.5)
            draw_mask += full_mask
            cv2.putText(im, '%s' % (class_name), (bbox[0]+5, bbox[1] + 12), cv2.FONT_HERSHEY_PLAIN,
								1.0, (255,255,255), thickness=1)
    return im 
开发者ID:guoruoqian,项目名称:cascade-rcnn_Pytorch,代码行数:25,代码来源:net_utils.py

示例2: draw_bboxes

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def draw_bboxes(img, bbox, identities=None, offset=(0,0)):
    for i,box in enumerate(bbox):
        x1,y1,x2,y2 = [int(i) for i in box]
        x1 += offset[0]
        x2 += offset[0]
        y1 += offset[1]
        y2 += offset[1]
        # box text and bar
        id = int(identities[i]) if identities is not None else 0    
        color = COLORS_10[id%len(COLORS_10)]
        label = '{} {}'.format("object", id)
        t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 2 , 2)[0]
        cv2.rectangle(img,(x1, y1),(x2,y2),color,3)
        cv2.rectangle(img,(x1, y1),(x1+t_size[0]+3,y1+t_size[1]+4), color,-1)
        cv2.putText(img,label,(x1,y1+t_size[1]+4), cv2.FONT_HERSHEY_PLAIN, 2, [255,255,255], 2)
    return img 
开发者ID:tensorboy,项目名称:centerpose,代码行数:18,代码来源:util.py

示例3: vis_detections

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def vis_detections(im, class_name, dets, gt_box, gt_center, num_box,
                   thresh=0.8):
    """Visual debugging of detections."""
    for i in range(np.minimum(300, dets.shape[0])):
        bbox = tuple(int(np.round(x)) for x in dets[i, :6])
        score = dets[i, -1]
        if score > thresh:
            cv2.rectangle(im, bbox[0:2], bbox[2:4], (0, 204, 0), 2)
            cv2.circle(im, (bbox[4], bbox[5]), 4, (0, 204, 0), -1)
            cv2.putText(im, '%s: %.3f' % (class_name, score),
                        (bbox[0], bbox[1] + 15), cv2.FONT_HERSHEY_PLAIN,
                        1.0, (0, 0, 255), thickness=1)
    # gt_box = gt_box[0]
    # gt_center = gt_center[0]
    # for i in range(num_box[0]):
    #     gtbox = tuple(int(np.round(x)) for x in gt_box[i, :4])
    #     gtcenter =  tuple(x for x in gt_center[i, :2])
    #     cv2.rectangle(im, gtbox[0:2], gtbox[2:4], (0, 0, 204), 2)
    #     cv2.circle(im, (gtcenter[0], gtcenter[1]), 4, (0, 0, 204), -1)
    return im 
开发者ID:ucbdrive,项目名称:3d-vehicle-tracking,代码行数:22,代码来源:net_utils.py

示例4: Visualize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def Visualize(self, mark1=None, mark2=None):
        img = self.figure.copy()
        if mark2:
            self.Mark( img, mark2, self.YELLOW)
        if mark1:
            self.Mark( img, mark1, self.RED)

        img = cv2.resize(img, (self.im_size, self.im_size))
        
        self.GetTime()
        cv2.putText(img, self.sort_title+" Time:%02.2fs"%self.time, (20,20), cv2.FONT_HERSHEY_PLAIN, 1, self.YELLOW, 1)

        if self.record:
            self.vdo_wtr.write(img)

        cv2.imshow(self.sort_title, img)

        if self.sound and mark1:
            self.PlaySound(mark1)
            pass

        cv2.waitKey(self.time_interval) 
开发者ID:ZQPei,项目名称:Sorting_Visualization,代码行数:24,代码来源:data.py

示例5: draw_boxes_and_caption

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def draw_boxes_and_caption(self, image_frame, v_boxes, v_labels, v_scores, show_names=False, show_percentage=False):

        for i in range(len(v_boxes)):
            box = v_boxes[i]
            y1, x1, y2, x2 = box.ymin, box.xmin, box.ymax, box.xmax
            width, height = x2 - x1, y2 - y1
            class_color = self.label_color(self.__labels.index(v_labels[i]))

            image_frame = cv2.rectangle(image_frame, (x1, y1), (x2, y2), class_color, 2)

            label = ""
            if show_names and show_percentage:
                label = "%s : %.3f" % (v_labels[i], v_scores[i])
            elif show_names:
                label = "%s" % (v_labels[i])
            elif show_percentage:
                label = "%.3f" % (v_scores[i])

            if show_names or show_percentage:
                b = np.array([x1, y1, x2, y2]).astype(int)
                cv2.putText(image_frame, label, (b[0], b[1] - 10), cv2.FONT_HERSHEY_PLAIN, 1, (200, 0, 0), 3)
                cv2.putText(image_frame, label, (b[0], b[1] - 10), cv2.FONT_HERSHEY_PLAIN, 1, (255, 255, 255), 2)

        return image_frame 
开发者ID:OlafenwaMoses,项目名称:ImageAI,代码行数:26,代码来源:__init__.py

示例6: clip_gradient

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def clip_gradient(model, clip_norm):
    """Computes a gradient clipping coefficient based on gradient norm."""
    totalnorm = 0
    clip_norm = torch.tensor([clip_norm], device='cuda')
    for p in model.parameters():
        if p.requires_grad:
            modulenorm = p.grad.data.norm()
            totalnorm += modulenorm ** 2
    totalnorm = np.sqrt(totalnorm).cuda()

    norm = clip_norm / max(totalnorm, clip_norm)
    for p in model.parameters():
        if p.requires_grad:
            p.grad.mul_(norm)
#
# def vis_detections(im, class_name, dets, thresh=0.8):
#     """Visual debugging of detections."""
#     for i in range(np.minimum(10, dets.shape[0])):
#         bbox = tuple(int(np.round(x)) for x in dets[i, :4])
#         score = dets[i, -1]
#         if score > thresh:
#             cv2.rectangle(im, bbox[0:2], bbox[2:4], (0, 204, 0), 2)
#             cv2.putText(im, '%s: %.3f' % (class_name, score), (bbox[0], bbox[1] + 15), cv2.FONT_HERSHEY_PLAIN,
#                         1.0, (0, 0, 255), thickness=1)
#     return im 
开发者ID:twangnh,项目名称:Distilling-Object-Detectors,代码行数:27,代码来源:net_utils.py

示例7: vis_detections

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def vis_detections(im, class_name, dets, thresh=0.8):
    """Visual debugging of detections."""
    for i in range(np.minimum(10, dets.shape[0])):
        bbox = tuple(int(np.round(x)) for x in dets[i, :4])
        score = dets[i, -1]
        if score > thresh:
##modify to use my draw box
            #previous draw box
            # cv2.rectangle(im, bbox[0:2], bbox[2:4], (0, 204, 0), 2)
            # cv2.putText(im, '%s: %.3f' % (class_name, score), (bbox[0], bbox[1] + 15), cv2.FONT_HERSHEY_PLAIN,
            #             3.0, (0, 0, 255), thickness=1)
            draw_box(im, bbox, label=class_name, conf=score)
            # im2show = cv2.resize(im, (960, 540))
            # cv2.imshow('test', im2show)
            # cv2.waitKey(0)
    return im 
开发者ID:twangnh,项目名称:Distilling-Object-Detectors,代码行数:18,代码来源:net_utils.py

示例8: plot_detections

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def plot_detections(image, tlbrs, scores=None, color=(255, 0, 0), ids=None):
    im = np.copy(image)
    text_scale = max(1, image.shape[1] / 800.)
    thickness = 2 if text_scale > 1.3 else 1
    for i, det in enumerate(tlbrs):
        x1, y1, x2, y2 = np.asarray(det[:4], dtype=np.int)
        if len(det) >= 7:
            label = 'det' if det[5] > 0 else 'trk'
            if ids is not None:
                text = '{}# {:.2f}: {:d}'.format(label, det[6], ids[i])
                cv2.putText(im, text, (x1, y1 + 30), cv2.FONT_HERSHEY_PLAIN, text_scale, (0, 255, 255),
                            thickness=thickness)
            else:
                text = '{}# {:.2f}'.format(label, det[6])

        if scores is not None:
            text = '{:.2f}'.format(scores[i])
            cv2.putText(im, text, (x1, y1 + 30), cv2.FONT_HERSHEY_PLAIN, text_scale, (0, 255, 255),
                        thickness=thickness)

        cv2.rectangle(im, (x1, y1), (x2, y2), color, 2)

    return im 
开发者ID:longcw,项目名称:MOTDT,代码行数:25,代码来源:visualization.py

示例9: generate_colorbar

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def generate_colorbar(self, min_temp=None, max_temp=None, cmap=cv.COLORMAP_JET, height=None):
        if min_temp is None:
            min_temp = self.global_min_temp
        if max_temp is None:
            max_temp = self.global_max_temp
        cb_gray = np.arange(255,0,-1,dtype=np.uint8).reshape((255,1))
        if cmap is not None:
            cb_color = cv.applyColorMap(cb_gray, cmap)
        else:
            cb_color = cv.cvtColor(cb_gray, cv.COLOR_GRAY2BGR)
        for i in range(1,6):
            cb_color = np.concatenate( (cb_color, cb_color), axis=1 )
        
        if height is None:
            append_img = np.zeros( (self.thermal_image.shape[0], cb_color.shape[1]+30, 3), dtype=np.uint8 )
        else:
            append_img = np.zeros( (height, cb_color.shape[1]+30, 3), dtype=np.uint8 )

        append_img[append_img.shape[0]//2-cb_color.shape[0]//2  : append_img.shape[0]//2 - (cb_color.shape[0]//2) + cb_color.shape[0] , 10 : 10 + cb_color.shape[1] ] = cb_color
        cv.putText(append_img, str(min_temp), (5, append_img.shape[0]//2 - (cb_color.shape[0]//2) + cb_color.shape[0] + 30), cv.FONT_HERSHEY_PLAIN, 1, (255,0,0) , 1, 8)
        cv.putText(append_img, str(max_temp), (5, append_img.shape[0]//2-cb_color.shape[0]//2-20) , cv.FONT_HERSHEY_PLAIN, 1, (0,0,255) , 1, 8 )
        return append_img 
开发者ID:detecttechnologies,项目名称:Thermal_Image_Analysis,代码行数:24,代码来源:CThermal.py

示例10: write

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def write(x, batches, results):
        c1 = tuple(x[1:3].int())
        c2 = tuple(x[3:5].int())
        img = results[int(x[0])]
        cls = int(x[-1])
        label = "{0}".format(classes[cls])
        color = random.choice(colors)
        cv2.rectangle(img, c1, c2,color, 1)
        t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 1 , 1)[0]
        c2 = c1[0] + t_size[0] + 3, c1[1] + t_size[1] + 4
        
        cv2.rectangle(img, c1, c2,color, -1)
        cv2.putText(img, label, (c1[0], c1[1] + t_size[1] + 4), cv2.FONT_HERSHEY_PLAIN, 1, [225,255,255], 1)
        cv2.imshow("res", img)
        cv2.waitKey(0)
        #cv2.imwrite("",cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
        return img 
开发者ID:avidLearnerInProgress,项目名称:pyCAIR,代码行数:19,代码来源:detect.py

示例11: draw_boxes

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def draw_boxes(img, output, offset=(0, 0)):
        for i, box in enumerate(output):
            x1, y1, x2, y2, identity = [int(ii) for ii in box]
            x1 += offset[0]
            x2 += offset[0]
            y1 += offset[1]
            y2 += offset[1]

            # box text and bar
            color = compute_color_for_labels(identity)
            label = '{}{:d}'.format("", identity)
            t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 2, 2)[0]
            cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
            cv2.rectangle(img, (x1, y1), (x1 + t_size[0] + 3, y1 + t_size[1] + 4), color, -1)
            cv2.putText(img, label, (x1, y1 + t_size[1] + 4), cv2.FONT_HERSHEY_PLAIN, 2, [255, 255, 255], 2)
        return img 
开发者ID:ZQPei,项目名称:deep_sort_pytorch,代码行数:18,代码来源:rtsp_threaded_tracker.py

示例12: draw_boxes

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def draw_boxes(img, bbox, identities=None, offset=(0,0)):
    for i,box in enumerate(bbox):
        x1,y1,x2,y2 = [int(i) for i in box]
        x1 += offset[0]
        x2 += offset[0]
        y1 += offset[1]
        y2 += offset[1]
        # box text and bar
        id = int(identities[i]) if identities is not None else 0    
        color = compute_color_for_labels(id)
        label = '{}{:d}'.format("", id)
        t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 2 , 2)[0]
        cv2.rectangle(img,(x1, y1),(x2,y2),color,3)
        cv2.rectangle(img,(x1, y1),(x1+t_size[0]+3,y1+t_size[1]+4), color,-1)
        cv2.putText(img,label,(x1,y1+t_size[1]+4), cv2.FONT_HERSHEY_PLAIN, 2, [255,255,255], 2)
    return img 
开发者ID:ZQPei,项目名称:deep_sort_pytorch,代码行数:18,代码来源:draw.py

示例13: draw_boxes

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def draw_boxes(self, img, frame_id, output, offset=(0, 0)):
        for i, box in enumerate(output):
            x1, y1, x2, y2, identity = [int(ii) for ii in box]
            self.logger.add_bbox_to_frame(frame_id=frame_id,
                                          bbox_id=identity,
                                          top=y1,
                                          left=x1,
                                          width=x2 - x1,
                                          height=y2 - y1)
            x1 += offset[0]
            x2 += offset[0]
            y1 += offset[1]
            y2 += offset[1]

            # box text and bar
            self.logger.add_label_to_bbox(frame_id=frame_id, bbox_id=identity, category='pedestrian', confidence=0.9)
            color = compute_color_for_labels(identity)
            label = '{}{:d}'.format("", identity)
            t_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_PLAIN, 2, 2)[0]
            cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
            cv2.rectangle(img, (x1, y1), (x1 + t_size[0] + 3, y1 + t_size[1] + 4), color, -1)
            cv2.putText(img, label, (x1, y1 + t_size[1] + 4), cv2.FONT_HERSHEY_PLAIN, 2, [255, 255, 255], 2)
        return img 
开发者ID:ZQPei,项目名称:deep_sort_pytorch,代码行数:25,代码来源:ped_det_server.py

示例14: write_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def write_text(frame=None, text=None, x=None,y=None, W=None, H=None, adjust=False):
    (tw, th) = cv2.getTextSize(text, cv2.FONT_HERSHEY_PLAIN, fontScale=g.args['fontscale'], thickness=2)[0]
    loc_x1 = x
    loc_y1 = y - th - 4
    loc_x2 = x + tw + 4
    loc_y2 = y

    if adjust:
        if not W or not H:
            fail_print('cannot auto adjust text as W/H  not provided')
        else:
            if loc_x1 + tw > W:
                loc_x1 = max (0, loc_x1 - (loc_x1+tw - W))
            if loc_y1 + th > H:
                loc_y1 = max (0, loc_y1 - (loc_y1+th - H))

    cv2.rectangle(frame, (loc_x1, loc_y1), (loc_x1+tw+4,loc_y1+th+4), (0,0,0), cv2.FILLED)
    cv2.putText(frame, text, (loc_x1+2, loc_y2-2), cv2.FONT_HERSHEY_PLAIN, fontScale=g.args['fontscale'], color=(255,255,255), thickness=1)
    return loc_x1, loc_y1, loc_x1+tw+4,loc_y1+th+4 
开发者ID:pliablepixels,项目名称:zmMagik,代码行数:21,代码来源:utils.py

示例15: extract_face_info

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FONT_HERSHEY_PLAIN [as 别名]
def extract_face_info(img, img_rgb, database,ear):
    faces = detector(img_rgb)
    x, y, w, h = 0, 0, 0, 0
    if len(faces) > 0:
        for face in faces:
            (x, y, w, h) = face_utils.rect_to_bb(face)
            cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2)
            image = img[y:y + h, x:x + w]
            name, min_dist = recognize_face(image, database)
            if ear > thresh:
                if min_dist < 0.1:
                    cv2.putText(img, "Face : " + name, (x, y - 50), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
                    cv2.putText(img, "Dist : " + str(min_dist), (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0), 2)
                else:
                    cv2.putText(img, 'No matching faces', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2)
            else:
                cv2.putText(img, 'Eyes Closed', (x, y - 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 255), 2) 
开发者ID:akshaybahadur21,项目名称:Facial-Recognition-using-Facenet,代码行数:19,代码来源:rec-feat.py


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