大家好,我目前正在做一个学校项目,甚至我的老师都很难过.在加拿大,便士已被删除,所以现在所有购买都被四舍五入为0或5.例如5.53将变为5.55,5.52将变为5.50.我试图让我的程序像这样循环,但我无法弄清楚如何.我知道如何舍入到小数位,但我不知道如何舍入到这样的细节.任何帮助,将不胜感激!
这是我的代码.该项目是关于制作出纳员将在咖啡店使用的程序.
order = ['coffee', 'tea', 'hashbrown','jelly','cream','chocolate','glazed','sandwich','bagel','cookie','pannini']
quantity = ['0','0','0','0','0','0','0','0','0','0','0']
# coffee = $1
# Tea = $1.30
# hashbrown = $1.25
# all donuts = $1.50
# sandwich = $2.50
# bagel = $2
# cookie = $0.50
# pannini = $4
cashier = 1
total = 0
while cashier == 1:
print "What did the customer order?"
ordered = input ()
while ordered > 10 or ordered < 0:
print "Do you want to input a valid order?" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Open CV缩小图像中的数字.我目前能够识别轮廓,但是一旦识别出数字,我就无法确定如何缩小数字.
以下是我发现的轮廓:
这是我用来实现这个目的的代码:
import cv2
image = cv2.imread("numbers.png")
edged = cv2.Canny(image, 10, 250)
# applying closing function
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
closed = cv2.morphologyEx(edged, cv2.MORPH_CLOSE, kernel)
_, cnts,_ = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
contours = []
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
contours.append(approx)
cv2.drawContours(image, [approx], -1, (0, 255, 0), 2)
cv2.imshow("Output", image)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
我希望能够使用轮廓缩小数字而不影响图像的大小.这可能吗?谢谢!