我想按顺序提取框中的数字。
原图
我使用分水岭算法来分隔连接到框的数字,但它不会正确地绘制数字轮廓,而是仅选择数字的某些部分。
#To get in big box that contain smaller boxes from the image
img = cv2.imread('1_6.png',0)
img = cv2.GaussianBlur(img,(3,3),1)
_,img = cv2.threshold(img,240,255,cv2.THRESH_BINARY)
img = cv2.GaussianBlur(img,(11,11),1)
edges = cv2.Canny(img,100,200)
_,c,h = cv2.findContours(edges.copy(),cv2.RETR_CCOMP,cv2.CHAIN_APPROX_NONE)
img = cv2.imread('1_6.png')
temp_c = sorted(c,key=cv2.contourArea,reverse=True)
#Select the big box
epsilon = 0.0001*cv2.arcLength(temp_c[0],True)
approx = cv2.approxPolyDP(temp_c[0],epsilon,True)
#Crop big box
pts = approx.copy()
rect = cv2.boundingRect(pts)
x,y,w,h = rect
croped = img[y:y+h, x:x+w].copy()
## (2) make mask
pts = pts - pts.min(axis=0)
mask = np.ones(croped.shape[:2], np.uint8)
cv2.drawContours(mask, [pts], …Run Code Online (Sandbox Code Playgroud) 我用一些数据训练了一个逻辑回归模型。我应用标准标量来训练和测试数据,训练模型。但是如果我想用训练和测试数据之外的数据对模型进行预测,我必须将标准标量应用于新数据,但是如果我有单个数据,我无法将标准标量应用于我想要的新单个样本给予作为输入。使用新数据(尤其是一次单个样本)预测结果的程序应该是什么?