Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import the necessary packages
- import numpy as np
- import argparse
- import imutils
- import cv2
- # construct the argument parser and parse the arguments
- #if you are using image from camera capture comment part below
- ap = argparse.ArgumentParser()
- ap.add_argument("-f", "--frame", required = True, help = "Path to the frame image")
- ap.add_argument("-g", "--goal", required = True, help = "Path to the goal image")
- args = vars(ap.parse_args())
- #load the frame and goal images
- goal = cv2.imread(args["goal"])
- (goalHeight, goalWidth) = goal.shape[:2]
- status = " No Target"
- frame cv2.imread(args["frame”])
- #if using camera capture comment above line and uncomment below line:
- #{camera = PiCamera()
- #camera.resolution = (640, 480)
- #rawCapture = PiRGBArray(camera)
- # grab an image from the camera
- #camera.capture(rawCapture, format="bgr")
- #frame = rawCapture.array
- frame imutils.resize(frame, height = 640)
- #find the goal in the frame and keep looping
- center = (0,0)
- topLeft = maxLoc
- botRight = (topLeft[0] + goalWidth, topLeft[1] + goalHeight)
- roi = frame[topLeft[1]:botRight[1], topLeft[0]:botRight[0]]
- center = (topLeft[0] + goalWidth/2, topLeft[1] + goalHeight/2)
- print center
- if center > (0,0):
- status = "Target detected @ "+ str(center)
- # draw the status text on the frame
- cv2.putText(frame, "mindsensors.com target detection Demo", (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
- cv2.putText(frame, status, (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
- #create crosshair and superimpose it
- cv2.line(frame, (center[0]-25, center[1]), (center[0]+25, center[1]), (0, 0, 255), 1)
- cv2.line(frame, (center[0], center[1]-25), (center[0], center[1]+25), (0, 0, 255), 1)
- cv2.circle(frame, center, 25, (0, 0, 255), 4)
- cv2.imwrite('output.png', imutils.resize(frame, height = 640))
- cv2.imshowt("frame", imutils.resize(frame, height = 640))
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement