remove scipy dependency, upscale preview image
This commit is contained in:
		
							
								
								
									
										29
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								main.py
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
# import the necessary packages
 | 
			
		||||
from scipy.spatial import distance as dist
 | 
			
		||||
#from scipy.spatial import distance as dist
 | 
			
		||||
from imutils import perspective
 | 
			
		||||
from imutils import contours
 | 
			
		||||
import numpy as np
 | 
			
		||||
@@ -26,6 +26,11 @@ def sizeVexScrew(iteml):
 | 
			
		||||
	iteml /= 8
 | 
			
		||||
	return iteml
 | 
			
		||||
	
 | 
			
		||||
def larger(a, b):
 | 
			
		||||
	if a >= b:
 | 
			
		||||
		return a
 | 
			
		||||
	else: 
 | 
			
		||||
		return b
 | 
			
		||||
 | 
			
		||||
# construct the argument parse and parse the arguments
 | 
			
		||||
ap = argparse.ArgumentParser()
 | 
			
		||||
@@ -45,6 +50,7 @@ if type(args["number"]) == type(selected):
 | 
			
		||||
 | 
			
		||||
# load the image, convert it to grayscale, and blur it slightly
 | 
			
		||||
image = cv2.imread(args["image"])
 | 
			
		||||
image = cv2.resize(image, (image.shape[1]*2, image.shape[0]*2), interpolation = cv2.INTER_AREA)
 | 
			
		||||
if args2.show:
 | 
			
		||||
	cv2.imshow("Image", image)
 | 
			
		||||
	cv2.waitKey(0)
 | 
			
		||||
@@ -142,8 +148,8 @@ for c in cnts:
 | 
			
		||||
	cv2.line(orig, (int(tlblX), int(tlblY)), (int(trbrX), int(trbrY)),
 | 
			
		||||
		(255, 0, 255), 2)
 | 
			
		||||
    	# compute the Euclidean distance between the midpoints
 | 
			
		||||
	dA = dist.euclidean((tltrX, tltrY), (blbrX, blbrY))
 | 
			
		||||
	dB = dist.euclidean((tlblX, tlblY), (trbrX, trbrY))
 | 
			
		||||
	dA = np.linalg.norm(np.array((tltrX, tltrY, 0)) - np.array((blbrX, blbrY, 0)))
 | 
			
		||||
	dB = np.linalg.norm(np.array((tlblX, tlblY, 0)) - np.array((trbrX, trbrY, 0)))
 | 
			
		||||
 | 
			
		||||
	# if the pixels per metric has not been initialized, then
 | 
			
		||||
	# compute it as the ratio of pixels to supplied metric
 | 
			
		||||
@@ -154,23 +160,18 @@ for c in cnts:
 | 
			
		||||
	dimA = dA / pixelsPerMetric
 | 
			
		||||
	dimB = dB / pixelsPerMetric
 | 
			
		||||
	
 | 
			
		||||
	if num == selected:
 | 
			
		||||
		itemw = dimA
 | 
			
		||||
		itemh = dimB
 | 
			
		||||
		if itemw >= itemh:
 | 
			
		||||
			iteml = itemw
 | 
			
		||||
		else:
 | 
			
		||||
			iteml = itemh
 | 
			
		||||
	if num == num:
 | 
			
		||||
		iteml = larger(dimA, dimB)
 | 
			
		||||
		print("Screw Length (RAW): " + str(iteml))
 | 
			
		||||
		iteml = sizeVexScrew(iteml)
 | 
			
		||||
		print("Rounded Length: " + str(iteml))
 | 
			
		||||
	# draw the object sizes on the image
 | 
			
		||||
		if args2.show:
 | 
			
		||||
			cv2.putText(orig, "{:.5f}in".format(dimA),
 | 
			
		||||
				(int(tltrX - 15), int(tltrY - 10)), cv2.FONT_HERSHEY_SIMPLEX,
 | 
			
		||||
			cv2.putText(orig, "{:.5f}in".format(larger(dimA, dimB)),
 | 
			
		||||
				(int(trbrX), int(trbrY)), cv2.FONT_HERSHEY_SIMPLEX,
 | 
			
		||||
				0.65, (255, 255, 255), 2)
 | 
			
		||||
			cv2.putText(orig, "{:.5f}in".format(dimB),
 | 
			
		||||
				(int(trbrX + 10), int(trbrY)), cv2.FONT_HERSHEY_SIMPLEX,
 | 
			
		||||
			cv2.putText(orig, "{:.3f}in".format(iteml), # print screw length
 | 
			
		||||
				(int(trbrX), int(trbrY + 20)), cv2.FONT_HERSHEY_SIMPLEX,
 | 
			
		||||
				0.65, (255, 255, 255), 2)
 | 
			
		||||
 
 | 
			
		||||
	# show the output image
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user