Make sure we can't take the log10 of 0

video
Cole Deck 4 years ago
parent fa15964b98
commit 4ca4d0c3cd

Binary file not shown.

@ -180,6 +180,7 @@ def detect(calibration_width, img_file, show, quick):
#orig = image.copy()
num += 1
# if the contour is not sufficiently large, ignore it
#pixelsPerMetric = 75
if cv2.contourArea(c) < 100 or pixelsPerMetric is None:
continue
# compute the rotated bounding box of the contour
@ -319,7 +320,8 @@ def detect(calibration_width, img_file, show, quick):
# cv2.putText(orig, "{:.5f}in".format(itemhr),
# (int(trbrX + 20), int(trbrY)), cv2.FONT_HERSHEY_SIMPLEX,
# 0.65, (255, 255, 255), 2)
#objtype = magicSort(c)
if objtype != "Penny":
objtype = magicSort(c)
if objtype == "Unknown":
objtype = magicSort(c)
output = "{:.2f}in".format(itemw) + " x {:.2f}in".format(itemh)
@ -370,6 +372,8 @@ def magicSort(contour):
#magicNumber2 = 0
name = "Unknown"
for i in range(0,7):
if humoments[i] == 0:
humoments[i] = 0.1;
humoments[i] = -1 * math.copysign(1.0, humoments[i]) * math.log10(abs(humoments[i]))
if i > 1:
humoments[i] = int(round(humoments[i][0] / 8) * 8)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 3.9 MiB

@ -8,9 +8,9 @@ import time
from imutils.video import FPS
calibration_width = 0.75
image = "img7.jpg"
images = ("img2.jpg", "img3.jpg", "img4.jpg", "img5.jpg", "img6.jpg", "img7.jpg", "img8.jpg")
images = ("img.jpg", "img3.jpg", "img4.jpg", "img5.jpg", "img6.jpg", "img7.jpg", "img8.jpg")
#images = ("img.jpg", "img2.jpg")
video = False
video = True
def go():
for file in images:
items,output = detect.detect(calibration_width, file, True, False)

Loading…
Cancel
Save