Python 作物图像在四
裁剪后的图像用cv2.imshow显示,但不能用cv2.imwrite保存 我尝试了输入变量和输出变量的类型是否有问题,他们都给出了numpy.ndarrayPython 作物图像在四,python,opencv,Python,Opencv,裁剪后的图像用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
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行,在Rectar_imagen中
cv2.imwritercropped_lu.jp,cropped_lu
AttributeError:“模块”对象没有属性“imwriter”
方法是cv2.imwrite not cv2.imwriter您想要编写imwrite not imwriter 我已经更正了它,但此错误标记为我的错误:/tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgcodecs/src/loadsave.cpp:677:error:-2无法在函数imwrite_u@DiegoDelezé中找到指定扩展名的编写器这是因为您试图使用.jp扩展名保存图像,而opencv无法处理该扩展名,因为它不是图像的正确扩展名此选项不提供问题的答案。若要评论或要求作者澄清,请在其帖子下方留下评论。-@这个答案确实解决了OPs的问题。OP在他们的代码中有一个输入错误,这个答案清楚地指出了这一点。OP在代码中还有其他问题,他们在这里要求它作为注释。@ShawnMathew不,它没有。还有其他错误,这个答案没有解决OP显然不能写两次相同的函数调用-在公共代码块的4个副本中,有4个不同的调用,大部分是不存在的函数。。此外,关于印刷错误的问题,这肯定是合格的,加上缺乏对细节的关注,甚至阅读文档,都是离题的。回答这个问题没有意义。由于生成错误的方法中的错误,投票关闭。不会捕获所有其他错误。老实说,有了60k rep,你为什么还要用一句话来回答这类公然离题的问题,而不是发表评论和示意结束?