

If the contour is not sufficiently large ( Lines 47 and 48), we ignore it. On Line 45 we start looping over each of the contours in the cnts list. # order, then draw the outline of the rotated bounding # in top-left, top-right, bottom-right, and bottom-left # order the points in the contour such that they appear # compute the rotated bounding box of the contourīox = cv2.cv.BoxPoints(box) if imutils.is_cv2() else cv2.boxPoints(box) # if the contour is not sufficiently large, ignore it We then initialize a list of colors used to draw the distances along with the refObj variable, which will store our bounding box, centroid, and pixels-per-metric value of the reference object. Since we know that our US quarter (i.e., the reference object) will always be the left-most object in the image, sorting the contours from left-to-right ensures that the contour corresponding to the reference object will always be the first entry in the cnts list. Once our image has been blurred, we apply the Canny edge detector to detect edges in the image - a dilation + erosion is then performed to close any gaps in the edge map ( Lines 28-30).Ī call to cv2.findContours detects the outlines of the objects in the edge map ( Lines 33-35) while Line 39 sorts our contours from left-to-right.

Lines 22-24 load our image from disk, convert it to grayscale, and then blur it using a Gaussian filter with a 7 x 7 kernel. # perform edge detection, then perform a dilation + erosion toĮdged = cv2.dilate(edged, None, iterations=1)Įdged = cv2.erode(edged, None, iterations=1)Ĭnts = cv2.findContours(py(), cv2.RETR_EXTERNAL, Gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) Next, we need to preprocess our image: # load the image, convert it to grayscale, and blur it slightly We need two switches here: -image, which is the path to the input image containing the objects we want to measure, and -width, the width (in inches) of our reference object. Lines 14-19 parse our command line arguments.
HOW TO LASER PROGRAM IN FABRIWIN 2016 INSTALL
Otherwise, you should upgrade to the latest version ( 0.3.6 at the time of this writing) so you have the updated order_points function: $ pip install -upgrade imutils If you don’t already have the imutils package installed, stop now to install it: $ pip install imutils

We start by importing our required Python packages on Lines 2-8.
HOW TO LASER PROGRAM IN FABRIWIN 2016 CODE
Our code here is near identical to last week. Help="width of the left-most object in the image (in inches)") # construct the argument parse and parse the argumentsĪp.add_argument("-i", "-image", required=True,Īp.add_argument("-w", "-width", type=float, required=True, Open up a new file, name it distance_between.py, and insert the following code: # import the necessary packagesįrom scipy.spatial import distance as dist Let’s go ahead and get this example started. Defining our reference object and computing distances Our goal in this image is to (1) find the quarter and then (2) use the dimensions of the quarter to measure the distance between the quarter and all other objects. We’ll also ensure that our quarter is always the left-most object in our image, thereby satisfying Property #2: Figure 1: We’ll identify our reference object based on location, hence we’ll always ensure our quarter is the left-most object in the image. Just as we did last week, we’ll be using a US quarter as our reference object which has a width of 0.955 inches (satisfying Property #1).
