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


Python cv2.FILLED属性代码示例

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


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

示例1: contour_filter

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def contour_filter(self, frame):
        _, contours, _ = cv2.findContours(frame,
            cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

        new_frame = np.zeros(frame.shape, np.uint8)
        for i, contour in enumerate(contours):
            c_area = cv2.contourArea(contour)
            if self.contour_min_area <= c_area <= self.contour_max_area:
                mask = np.zeros(frame.shape, np.uint8)
                cv2.drawContours(mask, contours, i, 255, cv2.FILLED)
                mask = cv2.bitwise_and(frame, mask)
                new_frame = cv2.bitwise_or(new_frame, mask)
        frame = new_frame

        if self.contour_disp_flag:
            frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
            cv2.drawContours(frame, contours, -1, (255, 0, 0), 1)

        return frame


    # A number of methods corresponding to the various trackbars available. 
开发者ID:jpnaterer,项目名称:smashscan,代码行数:24,代码来源:thresholding.py

示例2: drawBoundingBox

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [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

示例3: draw_boxes_frame

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def draw_boxes_frame(frame, frame_size, boxes_dicts, class_names, input_size):
  """Draws detected boxes in a video frame"""
  boxes_dict = boxes_dicts[0]
  resize_factor = (frame_size[0] / input_size[1], frame_size[1] / input_size[0])
  for cls in range(len(class_names)):
    boxes = boxes_dict[cls]
    color = (0, 0, 255)
    if np.size(boxes) != 0:
      for box in boxes:
        xy = box[:4]
        xy = [int(xy[i] * resize_factor[i % 2]) for i in range(4)]
        cv2.rectangle(frame, (xy[0], xy[1]), (xy[2], xy[3]), color[::-1], 2)
        (test_width, text_height), baseline = cv2.getTextSize(class_names[cls],
                                                              cv2.FONT_HERSHEY_SIMPLEX,
                                                              0.75, 1)
        cv2.rectangle(frame,
                      (xy[0], xy[1]),
                      (xy[0] + test_width, xy[1] - text_height - baseline),
                      color[::-1],
                      thickness=cv2.FILLED)
        cv2.putText(frame, class_names[cls], (xy[0], xy[1] - baseline), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 0), 1) 
开发者ID:kcosta42,项目名称:Tensorflow-YOLOv3,代码行数:23,代码来源:utils.py

示例4: drawBoundingBox

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [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

示例5: vis_det_and_mask

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [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

示例6: censor

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def censor(self, img_path, out_path=None, visualize=True, parts_to_blur=['BELLY', 'BUTTOCKS', 'F_BREAST', 'F_GENITALIA', 'M_GENETALIA', 'M_BREAST']):
        if not out_path and not visualize:
            print('No out_path passed and visualize is set to false. There is no point in running this function then.')

        image = cv2.imread(img_path)
        boxes = Detector.detect(self, img_path)
        boxes = [i['box'] for i in boxes if i['label'] in parts_to_blur]

        for box in boxes:
            part = image[box[1]:box[3], box[0]:box[2]]
            image = cv2.rectangle(image, (box[0], box[1]), (box[2], box[3]), (0, 0, 0), cv2.FILLED)
            # image = cv2.GaussianBlur(part,(23, 23), 30)
            # image[box[1]:box[3], box[0]:box[2]] = part
        
        if visualize:
            cv2.imshow("Blurred image", image)
            cv2.waitKey(0)
        
        if out_path:
            cv2.imwrite(out_path, image) 
开发者ID:notAI-tech,项目名称:NudeNet,代码行数:22,代码来源:detector.py

示例7: draw_debug_frame_for_object

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [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

示例8: drawPred

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def drawPred(frame,classId, conf, left, top, right, bottom):
    # Draw a bounding box.
    cv.rectangle(frame, (left, top), (right, bottom), (255, 178, 50), 3)
    
    label = '%.2f' % conf
        
    # Get the label for the class name and its confidence
    if classes:
        assert(classId < len(classes))
        label = '%s:%s' % (classes[classId], label)

    #Display the label at the top of the bounding box
    labelSize, baseLine = cv.getTextSize(label, cv.FONT_HERSHEY_SIMPLEX, 0.5, 1)
    top = max(top, labelSize[1])
    #cv.rectangle(frame, (left, top - round(1.5*labelSize[1])), (left + round(1.5*labelSize[0]), top + baseLine), (255, 255, 255), cv.FILLED)
    cv.putText(frame, label, (left, top), cv.FONT_HERSHEY_SIMPLEX, 0.75, (0,0,0), 1)

# Remove the bounding boxes with low confidence using non-maxima suppression 
开发者ID:holms-ur,项目名称:fine-tuning,代码行数:20,代码来源:predict.py

示例9: draw_box

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def draw_box(img, box, label='person', conf=None, color=(0, 255, 0)):
#in cv2, it is B G R not RBG
    # assert type(box) == list, 'box must be xmin, xmax, ymin, ymax'
    # xmin, xmax, ymin, ymax = box
    xmin, ymin, xmax, ymax = box
    xmin, xmax, ymin, ymax = int(xmin), int(xmax), int(ymin), int(ymax)
    img_box = np.copy(img)
    cv2.rectangle(img_box, (xmin, ymin), (xmax, ymax), color, 2)
    cv2.rectangle(img_box, (xmin - 1, ymin), (xmax + 1, ymin - 20), color, cv2.FILLED)
    font = cv2.FONT_HERSHEY_SIMPLEX
    if conf:
        cv2.putText(img_box, label, (xmin + 5, ymin - 5), font, 0.5,
                    (0, 0, 0), 2, 100)
        cv2.putText(img_box, '%.2f' % conf, (xmin + 5, ymin +20), font, 0.5,
                    (0, 0, 255), 2, 100)
    else:
        cv2.putText(img_box, label, (xmin + 5, ymin - 5), font, 1.0,
                    (0, 0, 0), 2, 100)
    alpha = 0.8
    cv2.addWeighted(img_box, alpha, img, 1. - alpha, 0, img) 
开发者ID:twangnh,项目名称:Distilling-Object-Detectors,代码行数:22,代码来源:net_utils.py

示例10: draw_result

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def draw_result(image, confidences, faceboxes):
    """Draw the detection result on image"""
    for result in zip(confidences, faceboxes):
        conf = result[0]
        facebox = result[1]

        cv.rectangle(image, (facebox[0], facebox[1]),
                     (facebox[2], facebox[3]), (0, 255, 0))
        label = "face: %.4f" % conf
        label_size, base_line = cv.getTextSize(
            label, cv.FONT_HERSHEY_SIMPLEX, 0.5, 1)

        cv.rectangle(image, (facebox[0], facebox[1] - label_size[1]),
                     (facebox[0] + label_size[0],
                      facebox[1] + base_line),
                     (0, 255, 0), cv.FILLED)
        cv.putText(image, label, (facebox[0], facebox[1]),
                   cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0)) 
开发者ID:yinguobing,项目名称:image_utility,代码行数:20,代码来源:face_detector.py

示例11: write_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [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

示例12: getHeadMask

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def getHeadMask(frame):

    th_val = 1

    ret, img_thresh = cv2.threshold(frame, th_val, 255, cv2.THRESH_BINARY)

    # Remove excess noise by drawing only the largest contour

    head_mask = np.zeros((img_thresh.shape[0], img_thresh.shape[1]), np.uint8)


    contours, hierarchy = cv2.findContours(img_thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[-2:]
    contours.sort(key=lambda ar: ar.size)
    head_contour = contours[-1]


    cv2.drawContours(head_mask, [head_contour], 0, 255, cv2.FILLED)

    return head_mask 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:21,代码来源:zebrafishAnalysis.py

示例13: _create_masks

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def _create_masks(size):
        # These masks are used to calculate the color difference between where the player indicator
        # should be and the area around it.  The masks are based on ratios, so they scale
        # to different input resolutions.
        #
        # The indicator_mask is 2 concentric circles that mask everything except the outer and
        # inner rings of the player indicator.
        #
        # The area_mask is the inverse of the indicator mask, limited to a small area right
        # around the indicator, this is used to get the mean color in the surrounding area.
        center = (size // 2, size // 2)

        mask_base = np.zeros((size, size, 1), np.uint8)

        ind_base = np.copy(mask_base)
        cv2.circle(ind_base, center, int(size * IND_OUTER_CIRCLE_RATIO), 255, thickness=2)
        cv2.circle(ind_base, center, int(size * IND_INNER_CIRCLE_RATIO), 255, thickness=1)
        _, indicator_mask = cv2.threshold(ind_base, 10, 255, cv2.THRESH_BINARY)

        area_base = np.copy(mask_base)
        cv2.circle(area_base, center, int(size * AREA_MASK_AREA_RATIO), 255, thickness=cv2.FILLED)
        cv2.circle(area_base, center, int(size * AREA_OUTER_CIRCLE_RATIO), 0, thickness=cv2.FILLED)
        _, area_mask = cv2.threshold(area_base, 10, 255, cv2.THRESH_BINARY)

        return indicator_mask, area_mask 
开发者ID:andrewzwicky,项目名称:PUBGIS,代码行数:27,代码来源:match.py

示例14: put_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def put_text(img, text):
    # (0,32),cv2.FONT_HERSHEY_PLAIN, 0.7, (255,255,255),1, cv2.LINE_4)
    font_scale = 0.7
    font = cv2.FONT_HERSHEY_PLAIN
    font_color = (255,255,255)
    thickness = cv2.LINE_4

    # set the rectangle background to black
    rectangle_bgr = (0, 0, 0)

    # get the width and height of the text box
    (text_width, text_height) = cv2.getTextSize(text, font, fontScale=font_scale, thickness=thickness)[0]
    # set the text start position
    text_offset_x = 0
    text_offset_y = img.shape[0]
    print(text_width, text_height)
    # make the coords of the box with a small padding of two pixels
    box_coords = ((text_offset_x, text_offset_y), (text_offset_x + text_width + 2, text_offset_y - text_height - 2))
    cv2.rectangle(img, box_coords[0], box_coords[1], rectangle_bgr, cv2.FILLED)
    cv2.putText(img, text, (text_offset_x, text_offset_y), font, fontScale=font_scale, color=font_color, thickness=1, lineType=cv2.LINE_4) 
    return img 
开发者ID:ag1le,项目名称:LSTM_morse,代码行数:23,代码来源:MorseDecoder.py

示例15: draw_label

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import FILLED [as 别名]
def draw_label(image, text, color, coords):
    font = cv2.FONT_HERSHEY_PLAIN
    font_scale = 1.
    (text_width, text_height) = cv2.getTextSize(text, font, fontScale=font_scale, thickness=1)[0]

    padding = 5
    rect_height = text_height + padding * 2
    rect_width = text_width + padding * 2

    (x, y) = coords

    cv2.rectangle(image, (x, y), (x + rect_width, y - rect_height), color, cv2.FILLED)
    cv2.putText(image, text, (x + padding, y - text_height + padding), font,
                fontScale=font_scale,
                color=(255, 255, 255),
                lineType=cv2.LINE_AA)

    return image 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:20,代码来源:utils.py


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