Обрезанные изображения отображаются с cv2.imshow
, но вы не можете сохранить их с помощью cv2.imwrite
Я попытался, если это проблема с входными переменными с выходными переменными с типом, и все они дали Numpy.ndarray
import numpy as np
import cv2
def recotar_imagen(gray):
#Read the image
gray = cv2.imread('imagengris.jpg')
print type (gray)
#Means of the image within a matrix
heigth, width = gray.shape[:2]
n = width
h = heigth
x = 0
y = 0
#Formulas for half of the image in x y
x2 = int(round ((n-1)/2))
y2 = int(round ((h-1)/2))
x3 = x2 + 1
y3 = y2 + 1
#Operator for the first image
#cropped_lu is for the image on the left above
cropped_lu = gray[x:x2, y:y2]
print type (cropped_lu)
cv2.imshow("cropped_lu.jpg", cropped_lu)
cv2.imwriter("cropped_lu.jp", cropped_lu)
#Operator for the second image
#cropped_ru is for the image on the right above
cropped_ru = gray[x3:n-1, y:y2]
print type (cropped_ru)
cv2.imshow("cropped_ru.jpg", cropped_ru)
cv2.write("cropped_ru.jpg", cropped_ru)
#Operator for the third image
#cropped_ld is for the image on the left below
cropped_ld = gray[x:x2, y3:h-1]
print type (cropped_ld)
cv2.imshow("cropped_ld.jpg", cropped_ld)
cv2.imsave("cropped_ld.jpg", cropped_ld)
#Operator for the fourth image
#cropped_ld is for the image on the right below
cropped_rd = gray[x2:n-1, y3:h-1]
print type (cropped_rd)
cv2.imshow("cropped_rd.jpg", cropped_rd)
cv2.imwrite("cropped_rd.jpg", cropped_rd)
cv2.waitKey(0)
cv2.destroyAllWindows()
Журнал ошибок
строка 55, в recotar_imagen cv2.imwriter ("cropped_lu.jp", cropped_lu)
AttributeError: 'module'объект не имеет атрибута «imwriter»