问题描述
在spyder 4.1.3in spyder中4.1.3in spyder 4.1.3in spyder 4.1.3in spyder 4.1.3in spyder 4.1.3in spyder 4.1.3in spyder 4.1.3in spyder 4.1.3in spyder 4.1.3in spyder中的一些细节。添加更多细节,添加更多细节,添加更多细节,添加更多细节,添加更多细节,添加更多细节,添加更多细节,添加更多细节,添加更多细节,添加更多细节。
错误是:
runfile('D:/projects/task3/a.py',wdir='D:/projects/task3')
This command failed to be executed because an error occurred while trying to get the file code from Spyder's editor. The error was:
An exception has occurred,use %tb to see the full traceback.
TypeError: handle_get_file_code() got an unexpected keyword argument 'save_all'
%tb
Traceback (most recent call last):
File "C:\Users\zzh\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",line 463,in get_file_code
filename,save_all=save_all)
File "C:\Users\zzh\anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py",line 550,in __call__
call_dict,call_data,self._comm_id)
File "C:\Users\zzh\anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py",line 432,in _get_call_return_value
return self._sync_error(reply['value'])
File "C:\Users\zzh\anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py",line 488,in _sync_error
error_wrapper.raise_error()
File "C:\Users\zzh\anaconda3\lib\site-packages\spyder_kernels\comms\commbase.py",line 90,in raise_error
raise self.etype(self)
TypeError: handle_get_file_code() got an unexpected keyword argument 'save_all'
我想获得图片的边缘,这是我的源代码:
import cv2
import numpy as np
from PIL import Image
img = Image.open("./test.png")
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img_gauss_blur = cv2.GaussianBlur(img_gray,(5,5),0)
img_canny = cv2.Canny(img_gray,34,158)
contours,h = cv2.findContours(img_canny,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
length = []
for i,contour in enumerate(contours):
length.append(cv2.arcLength(contour,True))
index = np.argmax(length)
def s(con):
return cv2.arcLength(con,True)
cnts = sorted(contours,key = s,reverse=True)[:1]
long = cv2.arcLength(cnts[0],True)
approx = cv2.approxPolyDP(cnts[0],0.1*long,True)
res = cv2.drawContours(img.copy(),[approx],-1,(0,255),2)
tr = approx[0][0]
br = approx[1][0]
bl = approx[2][0]
tl = approx[3][0]
widthr = int(np.sqrt((br[0]-tr[0])**2+(br[1]-tr[1])**2))
widthl = int(np.sqrt((bl[0]-tl[0])**2+(bl[1]-tl[1])**2))
width = np.max((widthr,widthl))
heightb = int(np.sqrt((br[0]-bl[0])**2+(br[1]-bl[1])**2))
heightt = int(np.sqrt((tr[0]-tl[0])**2+(tr[1]-tl[1])**2))
height = np.max((heightb,heightt))
old_point = np.array([tl.tolist(),tr.tolist(),br.tolist(),bl.tolist()],np.float32)
new_point = np.array([[0,height-1],[0,0],[width-1,height-1]],np.float32)
M = cv2.getPerspectiveTransform(old_point,new_point)
new_image = cv2.warpPerspective(img,M,(width-1,height-1))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)