Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. # import the necessary packages
  2. import numpy as np
  3. import argparse
  4. import imutils
  5. import cv2
  6.  
  7. # construct the argument parser and parse the arguments
  8. #if you are using image from camera capture comment part below
  9. ap = argparse.ArgumentParser()
  10.  
  11. ap.add_argument("-f", "--frame", required = True, help = "Path to the frame image")
  12. ap.add_argument("-g", "--goal", required = True, help = "Path to the goal image")
  13. args = vars(ap.parse_args())
  14.  
  15. #load the frame and goal images
  16. goal = cv2.imread(args["goal"])
  17. (goalHeight, goalWidth) = goal.shape[:2]
  18. status = " No Target"
  19.  
  20. frame cv2.imread(args["frame”])
  21.  
  22. #if using camera capture comment above line and uncomment below line:
  23. #{camera = PiCamera()
  24. #camera.resolution = (640, 480)
  25. #rawCapture = PiRGBArray(camera)
  26. # grab an image from the camera
  27. #camera.capture(rawCapture, format="bgr")
  28. #frame = rawCapture.array
  29.  
  30. frame imutils.resize(frame, height = 640)
  31.  
  32. #find the goal in the frame and keep looping
  33. center = (0,0)
  34. topLeft = maxLoc
  35. botRight = (topLeft[0] + goalWidth, topLeft[1] + goalHeight)
  36. roi = frame[topLeft[1]:botRight[1], topLeft[0]:botRight[0]]
  37. center = (topLeft[0] + goalWidth/2, topLeft[1] + goalHeight/2)
  38. print center
  39. if center > (0,0):
  40. status = "Target detected @ "+ str(center)
  41. # draw the status text on the frame
  42. cv2.putText(frame, "mindsensors.com target detection Demo", (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
  43. cv2.putText(frame, status, (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
  44. #create crosshair and superimpose it
  45. cv2.line(frame, (center[0]-25, center[1]), (center[0]+25, center[1]), (0, 0, 255), 1)
  46. cv2.line(frame, (center[0], center[1]-25), (center[0], center[1]+25), (0, 0, 255), 1)
  47. cv2.circle(frame, center, 25, (0, 0, 255), 4)
  48.  
  49. cv2.imwrite('output.png', imutils.resize(frame, height = 640))
  50. cv2.imshowt("frame", imutils.resize(frame, height = 640))
  51.  
  52. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement