Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'numpy.ndarray' object has no attribute 'save'

i have short code for crop image all image in folder that i labeled and save as csv using opencv like this:

import os, sys
from PIL import Image
import cv2
import pandas as pd

# The annotation file consists of image names, text label, 
# bounding box information like xmin, ymin, xmax and ymax.
ANNOTATION_FILE = 'data/annot_crop_plate.csv'
df = pd.read_csv(ANNOTATION_FILE)

#image directory path
IMG_DIR = 'data/images'
# The cropped images will be stored here
CROP_DIR = 'data/crops'

files = df['filename']

size = (200,200)

for file in files:
    print(file)
    img = cv2.imread(IMG_DIR +'/' + file)
    annot_data = df[df['filename'] == file]
    xmin = int(annot_data['xmin'])
    ymin = int(annot_data['ymin'])
    xmax = int(annot_data['xmax'])
    ymax = int(annot_data['ymax'])
    crop = img[ymin:ymax,xmin:xmax]
    new_crop = cv2.resize(crop, dsize=size, interpolation=cv2.INTER_CUBIC)
    new_crop.save(CROP_DIR + '/' + file.split('.')[0] + '.png', 'PNG', quality=90)

but in the end of line have said "AttributeError: 'numpy.ndarray' object has no attribute 'save'"

like image 659
scalartensor Avatar asked Dec 23 '22 18:12

scalartensor


1 Answers

try using

cv2.imwrite(path,img_to_save)

in the last line.

like image 168
Ishwar Ramdasi Avatar answered Dec 25 '22 08:12

Ishwar Ramdasi