Python Forum
Real time Detection and Display
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Real time Detection and Display
#1
Hello all! :)

I'm trying to automate a mini-game inside 'Star Trek Online' where you have 4 rows and you have to point the mouse on the right row when the object coming from the left is on a pixel / area.

example for full mini-game:
[Image: 2015-01-29_2357.png]

[Image: Omega-Board.jpg]



Example for location marks:
[Image: example.jpg]

I've managed to get to the point where I can see both the screen capture and the detection but if I move the mini-game box then the detection marks don't adjust.

I also tried to use threading but got the same results. detection markers stays in one place.
how can I tweak the code so the detection marks will move according to the real time screen capturing?

liveImage = r'path to screenshot'
OMEGA_BOARD_MAIN = r'path to mini-game board'

def omega():
    def draw():
        line_color = (0, 255, 0)
        line_type = cv2.LINE_4
        marker_color = (255, 0, 255)
        marker_type = cv2.MARKER_CROSS
        cv2.rectangle(frame, loc[0], (loc[0][0] + w, loc[0][1] + h), (255, 0, 255), 1)  # BLUE

        # Marker Row 1
        cv2.drawMarker(frame, ((int(loc[0][0] + w) - 332), (int(loc[0][1] + h)) - 200),
                       color=marker_color, markerType=marker_type, markerSize=40, thickness=1)

        # Marker Row 2
        cv2.drawMarker(frame, ((int(loc[0][0] + w) - 332), (int(loc[0][1] + h)) - 155),
                       color=marker_color, markerType=marker_type, markerSize=40, thickness=1)

        # Marker Row 3
        cv2.drawMarker(frame, ((int(loc[0][0] + w) - 332), (int(loc[0][1] + h)) - 80),
                       color=marker_color, markerType=marker_type, markerSize=40, thickness=1)

        # Marker Row 4
        cv2.drawMarker(frame, ((int(loc[0][0] + w) - 332), (int(loc[0][1] + h)) - 30),
                       color=marker_color, markerType=marker_type, markerSize=40, thickness=1)

    screenshot()
    while True:
        img_rgb = cv2.imread(liveImage)
        img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
        template = cv2.imread(OMEGA_BOARD_MAIN, 0)
        w, h = template.shape[::-1]

        res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
        threshold = 0.5
        loc = np.where(res >= threshold)
        loc = list(zip(*loc[::-1]))

        imgScreen = np.array(ImageGrab.grab(bbox=(0, 0, 1920, 1080)))
        frame = cv2.cvtColor(imgScreen, cv2.COLOR_RGB2BGR)

        if len(loc):
            row1_x, row1_y = (loc[0][0] + w) - 332, (loc[0][1] + h) - 200
            row2_x, row2_y = (loc[0][0] + w) - 332, (loc[0][1] + h) - 155
            row3_x, row3_y = (loc[0][0] + w) - 332, (loc[0][1] + h) - 80
            row4_x, row4_y = (loc[0][0] + w) - 332, (loc[0][1] + h) - 30
            draw()

        else:
            print("No Omega Board Found.")

        cv2.imshow('omega', frame)
        if cv2.waitKey(1) == ord('q'):
            cv2.destroyAllWindows()
            quit()


omega()
Thank you for your time! :)

EDIT:
solution was to change the template match to capture the frame.
Solved! please close.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,702 May-06-2023, 08:14 AM
Last Post: pramod08728
  Non-blocking real-time plotting slow_rider 5 3,453 Jan-07-2023, 09:47 PM
Last Post: woooee
  Real time database satyanarayana 3 1,623 Feb-16-2022, 01:37 PM
Last Post: buran
  Real time data satyanarayana 3 20,190 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  Real-Time output of server script on a client script. throwaway34 2 2,010 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 3,880 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
Question I can't get my real-time chart with Python (Help!) Bastian_ElProfe 1 2,188 Jan-20-2021, 01:34 PM
Last Post: wostan
  Real Time signal processing tagalog 2 2,600 Dec-12-2020, 05:23 AM
Last Post: tagalog
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,172 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  Real-time processing tagalog 5 3,062 Oct-06-2020, 03:45 PM
Last Post: tagalog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020