本文整理汇总了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
示例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
示例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)
示例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
示例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
示例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)
示例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)
示例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