Skip to content

Instantly share code, notes, and snippets.

@potix2
Created November 17, 2016 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potix2/202655360338a799a1138c96fb75f41a to your computer and use it in GitHub Desktop.
Save potix2/202655360338a799a1138c96fb75f41a to your computer and use it in GitHub Desktop.
simple target dtection
#!/usr/bin/env python
import cv2
import numpy
# read png image and convert the image to HSV
image = cv2.imread("/path/to/target.png", cv2.IMREAD_COLOR)
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# detect green objects
lower_green = numpy.array([133 / 2 - 10, 62 * 255 / 100 - 30, 37 * 255 / 100 - 30], numpy.uint8)
upper_green = numpy.array([133 / 2 + 10, 62 * 255 / 100 + 30, 37 * 255 / 100 + 30], numpy.uint8)
mask = cv2.inRange(hsv, lower_green, upper_green)
cv2.imshow('original', image)
cv2.imshow('mask', mask)
cv2.imwrite("hsv_mask.png", mask)
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment