2019-11-13 11:58:45 +00:00
|
|
|
from systems.fishing_event import *
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2019-02-16 11:32:20 +00:00
|
|
|
def GetKeypointFromImage(img):
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
convert image int hsv
|
|
|
|
creates a mask for brown color
|
|
|
|
uses blob detection to find a blob in the mask
|
|
|
|
filter the blobs to find the correct one
|
|
|
|
|
|
|
|
:param img: rgb image
|
|
|
|
:return: location of the pixel which is used to detect different fishing states
|
|
|
|
"""
|
|
|
|
|
2019-02-16 11:32:20 +00:00
|
|
|
# Setup SimpleBlobDetector parameters.
|
|
|
|
hsvImg = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
|
|
|
|
lower = (99, 254, 100)
|
|
|
|
upper = (100, 255, 101)
|
|
|
|
mask = cv2.inRange(hsvImg, lower, upper)
|
|
|
|
|
|
|
|
# Setup SimpleBlobDetector parameters.
|
|
|
|
params = cv2.SimpleBlobDetector_Params()
|
|
|
|
|
|
|
|
# Change thresholds
|
|
|
|
params.minThreshold = 10
|
|
|
|
params.maxThreshold = 255
|
|
|
|
|
|
|
|
params.filterByColor = True
|
|
|
|
params.blobColor = 255
|
|
|
|
|
|
|
|
params.filterByCircularity = False
|
|
|
|
params.filterByConvexity = False
|
|
|
|
params.filterByInertia = False
|
|
|
|
|
|
|
|
params.filterByArea = True
|
|
|
|
params.minArea = 10.0
|
|
|
|
|
|
|
|
detector = cv2.SimpleBlobDetector_create(params)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2019-02-16 11:32:20 +00:00
|
|
|
# Detect blobs.
|
|
|
|
keypoints = detector.detect(mask)
|
|
|
|
|
|
|
|
if len(keypoints) <= 0:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return int(keypoints[0].pt[0]), int(keypoints[0].pt[1])
|
|
|
|
|
|
|
|
|
|
|
|
class PixelLoc:
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
finds the pixel loc and store it
|
|
|
|
"""
|
|
|
|
|
2019-02-16 11:32:20 +00:00
|
|
|
val = None
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2019-02-16 11:32:20 +00:00
|
|
|
def config():
|
2019-06-29 20:35:53 +00:00
|
|
|
"""
|
|
|
|
Uses the game window to get an image of the game screen
|
|
|
|
then uses `GetKeypointFromImage()` to find the ProvisionsChalutier pixel location
|
|
|
|
:return: false if pixel loc not found
|
|
|
|
"""
|
2019-02-16 11:32:20 +00:00
|
|
|
|
2019-11-13 11:58:45 +00:00
|
|
|
PixelLoc.val = (0, 0, 1, 1)
|
2019-02-16 11:32:20 +00:00
|
|
|
|
|
|
|
return True
|