【问题标题】:Annotation JPEG problems注释 JPEG 问题
【发布时间】:2018-08-13 16:16:24
【问题描述】:

好的,所以我有这些注释功能

def rotate_bound(image, angle):
    # grab the dimensions of the image and then determine the
    # center
    (h, w) = image.shape[:2]
    (cX, cY) = (w // 2, h // 2)

    # grab the rotation matrix (applying the negative of the
    # angle to rotate clockwise), then grab the sine and cosine
    # (i.e., the rotation components of the matrix)
    M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)
    cos = np.abs(M[0, 0])
    sin = np.abs(M[0, 1])

    # compute the new bounding dimensions of the image
    nW = int((h * sin) + (w * cos))
    nH = int((h * cos) + (w * sin))

    # adjust the rotation matrix to take into account translation
    M[0, 2] += (nW / 2) - cX
    M[1, 2] += (nH / 2) - cY

    # perform the actual rotation and return the image
    return cv2.warpAffine(image, M, (nW, nH), borderValue=(255, 255, 255))

def blur_image(image, radius):
    pil_img = Image.fromarray(image)
    pil_img = pil_img.filter(ImageFilter.GaussianBlur(radius=radius))
    opencv_image = np.array(pil_img)
    return opencv_image

def enhance_brightness(image, value):
    for x in range(image.shape[0]):
        for y in range(image.shape[1]):
            if image[x][y][0] < 245 and image[x][y][1] < 245 and image[x][y][2] < 245:
                if image[x][y][0] + value <= 255 and image[x][y][0] + value >= 0:
                    image[x][y][0] += value
                if image[x][y][1] + value <= 255 and image[x][y][0] + value >= 0:
                    image[x][y][1] += value
                if image[x][y][2] + value <= 255 and image[x][y][0] + value >= 0:
                    image[x][y][2] += value

    return image

当我尝试使用它们时,我遇到了无法修复的错误。

rotate_bound 和 enhance_brightness 两个函数都给出相同的错误:

'JpegImageFile' object has no attribute 'shape'. 

而blur 函数返回另一个错误:

a bytes-like object is required, not 'JpegImageFile'

如果有人帮我一把,我会很高兴的。

【问题讨论】:

  • 什么是图像?你能显示你定义图像的代码吗?
  • img=Image.open("test.jpg") 我尝试了 jpg 和 png 格式,它仍然给我错误

标签: python numpy opencv


【解决方案1】:

您正在使用 Pillow 导入图像。枕头没有“形状”属性。相反,尝试

img = cv2.imread("test.jpg")

这应该可以解决所有问题。

【讨论】:

  • 这解决了问题,感谢您的快速回答:)
  • 别担心,乐于助人:)
猜你喜欢
  • 2012-06-10
  • 1970-01-01
  • 2017-10-27
  • 2018-06-28
  • 2017-12-03
  • 2021-03-22
  • 1970-01-01
  • 1970-01-01
  • 2017-03-04
相关资源
最近更新 更多