无法使用opencv保存增强图像

webghufk  于 2023-04-07  发布在  其他
关注(0)|答案(1)|浏览(133)

我正在增强数据,之后我使用opencv将增强的图像保存到文件夹中,但它给出了一个错误。
下面的代码我试过了:

aug_dir = '/content/gdrive/MyDrive/augment_images/resized_224'

for i in range(1, 5):
  filename = "/content/gdrive/MyDrive/augment_images/{}.jpg".format(i)
  img = imaugs.resize(filename, width = 224, height = 224)

  #save image
  cv2.imwrite("/content/gdrive/MyDrive/augment_images/resized_224/{}.jpg".format(i),img)

错误

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-7-58253ac0f107> in <cell line: 3>()
      7 
      8   #save image
----> 9   cv2.imwrite("/content/gdrive/MyDrive/augment_images/resized_224/{}.jpg".format(i),img)
     10 
     11 

error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imwrite'
> Overload resolution failed:
>  - img is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'img'

我想增强图像保存在一个文件夹使用opencv

goqiplq2

goqiplq21#

img = cv2.imread('images/dog.jpg')
print(img.shape)
width, height = 224, 224
resize_image = cv2.resize(img, dsize=(width, height))
print(resize_image.shape)
cv2.imwrite('aug_images/dog_{}_{}.jpg'.format(width, height), resize_image)

相关问题