當前位置: 首頁>>代碼示例>>Python>>正文


Python imutils.rotate_bound方法代碼示例

本文整理匯總了Python中imutils.rotate_bound方法的典型用法代碼示例。如果您正苦於以下問題:Python imutils.rotate_bound方法的具體用法?Python imutils.rotate_bound怎麽用?Python imutils.rotate_bound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在imutils的用法示例。


在下文中一共展示了imutils.rotate_bound方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: rotate

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def rotate(self, degree):
        """ rotate the image """
        if not isinstance(degree, int):
            raise ValueError("Degree must be an integer")

        if degree <= -360 or degree >= 360:
            raise ValueError("Degree must be between -360 and 360")

        # rotate the image
        rotated = imutils.rotate_bound(self._imgdata, degree)

        # resize back to expected dimensions
        if degree not in [0, 90, 180, 270, -90, -180, -270]:
            # resize takes only height x width
            shape = (self._imgdata.shape[0], self._imgdata.shape[1])
            rotated = cv2.resize(rotated, shape, interpolation=cv2.INTER_AREA)
        return rotated 
開發者ID:andrewferlitsch,項目名稱:Gap,代碼行數:19,代碼來源:vision.py

示例2: load_vid

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def load_vid(vid_file,rotation=None):
    vid = []
    if rotation is None:
        rotation = _ffmpeg_extract_rotation(vid_file)
    videogen = cv2.VideoCapture(vid_file)
    while True:
        ret,im = videogen.read()
        if not ret:
            break
        im = imutils.rotate_bound(im,rotation-360)
        vid.append(im)
    videogen.release()
    return vid 
開發者ID:AruniRC,項目名稱:detectron-self-train,代碼行數:15,代碼來源:convert_fddb_to_json.py

示例3: save_vid_frames

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def save_vid_frames(vid_name,vid_file_path,frame_list,save_det_dir,rotation=None):
    vid = load_vid(vid_file_path,rotation=rotation)
    for frame_id_str in frame_list:
        frame_id = int(frame_id_str)
        frame = imutils.rotate_bound(vid[frame_id],rotation-360)
        cv2.imwrite(os.path.join(save_det_dir,vid_name+'_'+frame_id_str+'.jpg'),frame)
    del(vid) 
開發者ID:AruniRC,項目名稱:detectron-self-train,代碼行數:9,代碼來源:fast_convert_fddb_to_json.py

示例4: apply_sprite

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def apply_sprite(image, path2sprite, w, x, y, angle, ontop=True):
    sprite = cv2.imread(path2sprite, -1)
    # print sprite.shape
    sprite = rotate_bound(sprite, angle)
    (sprite, y_final) = adjust_sprite2head(sprite, w, y, ontop)
    image = draw_sprite(image, sprite, x, y_final)


# points are tuples in the form (x,y)
# returns angle between points in degrees 
開發者ID:charlielito,項目名稱:snapchat-filters-opencv,代碼行數:12,代碼來源:main_dlib.py

示例5: apply_sprite

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def apply_sprite(image, path2sprite,w,x,y, angle, ontop = True):
    sprite = cv2.imread(path2sprite,-1)
    #print sprite.shape
    sprite = rotate_bound(sprite, angle)
    (sprite, y_final) = adjust_sprite2head(sprite, w, y, ontop)
    image = draw_sprite(image,sprite,x, y_final)

#points are tuples in the form (x,y)
# returns angle between points in degrees 
開發者ID:scalability4all,項目名稱:voice-enabled-chatbot,代碼行數:11,代碼來源:dog.py

示例6: rotate_file_image

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def rotate_file_image(filename, Alpha):
    img=cv2.imread(filename,1)
    dst=imutils.rotate_bound(img,Alpha)
    w_n,h_n,d_n=dst.shape
    file_rotate_image=str(Alpha)+filename
    Alpha=-1*Alpha
    cv2.imwrite(file_rotate_image,dst)
    file_annotate=filename.replace("png", "xml")
    file_annotate_rotate=file_rotate_image.replace("png", "xml")
    copy_file(file_annotate,file_annotate_rotate)
    rotate_xml(file_annotate_rotate, Alpha,w_n, h_n) 
開發者ID:manhcuogntin4,項目名稱:Label-Annotation-VOC-Pascal,代碼行數:13,代碼來源:read_xml_correct_rotation_left.py

示例7: rotate_file_image

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def rotate_file_image(filename, Alpha):
    img=cv2.imread(filename,1)
    dst=imutils.rotate_bound(img,Alpha)
    w_n,h_n,d_n=dst.shape
    file_rotate_image=str(Alpha)+filename
    cv2.imwrite(file_rotate_image,dst)
    file_annotate=filename.replace("png", "xml")
    file_annotate_rotate=file_rotate_image.replace("png", "xml")
    copy_file(file_annotate,file_annotate_rotate)
    rotate_xml(file_annotate_rotate, Alpha,w_n, h_n) 
開發者ID:manhcuogntin4,項目名稱:Label-Annotation-VOC-Pascal,代碼行數:12,代碼來源:read_xml_correct_rotation.py

示例8: applyOcr

# 需要導入模塊: import imutils [as 別名]
# 或者: from imutils import rotate_bound [as 別名]
def applyOcr(imgUrl):
    """
    Open an image and read its letters.
    :param imgUrl: The URL for a CAPTCHA image.
    :return: The string in the imgae.
    """
    response = urlopen("file://" + imgUrl)
    img = np.asarray(bytearray(response.read()), dtype="uint8")
    gray_img = cv2.imdecode(img, cv2.IMREAD_GRAYSCALE)
    # if it's black on white:
    gray_img = 255 - gray_img
    _, mask = cv2.threshold(gray_img, THRESHOLD, 255, cv2.THRESH_BINARY)
    mask, contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    letters = {}  # x coordinate ↦ predicted letter
    for c, contour in enumerate(contours):
        rect = cv2.minAreaRect(contour)  # Find a rotated bounding box
        # rect is a tuple: ((corner 1, corner2), angle)
        angle = adjustAngle(rect[-1])
        # Draw this contour
        letter_mask = np.zeros(mask.shape, dtype="uint8")
        letter_mask = cv2.drawContours(letter_mask, [contour], contourIdx=0, color=255,
                                       thickness=-1)
        segmented_img = cv2.bitwise_and(gray_img, gray_img, mask=letter_mask)  # Applying mask
        dark_spun = imutils.rotate_bound(segmented_img, -angle)
        """
        We could crop the letter, but Tesseract doesn't seem to like such tight margins.
        brightPixels = cv2.findNonZero(dark_spun)
        x, y, width, height = cv2.boundingRect(brightPixels)
        cropped = darkSpun[y:y+height, x:x+width]
        """
        colored = cv2.cvtColor(dark_spun, cv2.COLOR_GRAY2RGB)
        colored = 255 - colored
        pil_image = Image.fromarray(colored)
        char_result = image_to_string(pil_image, config="--psm 10 --oem 0")
        if char_result is not None and len(char_result) > 0:
            moments = cv2.moments(contour)
            xCentre = int(moments["m10"]/moments["m00"])
            while xCentre in letters:
                xCentre += 1  # Avoid key clash
            letters[xCentre] = char_result.upper()
            if logger.getEffectiveLevel() <= logging.DEBUG:
                scipy.misc.imsave(char_result + ".jpg", pil_image)
        else:
            logger.debug("No result for character %d", c)
            if logger.getEffectiveLevel() <= logging.DEBUG:
                scipy.misc.imsave("unknown letter {c}.jpg".format(c=c), pil_image)
    # Adjust letters based on X axis
    word_solution = ""
    for xCentre in sorted(letters.keys()):
        word_solution += letters[xCentre]
    logger.debug("OCR saw %s", word_solution)
    return word_solution 
開發者ID:owen9825,項目名稱:captcha-middleware,代碼行數:54,代碼來源:solver.py


注:本文中的imutils.rotate_bound方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。