Python Forum
need help on solving and movement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help on solving and movement
#1
hi guys, I hope you guys can give me some advice, even if you can this point me in a direction, please.
the folwing is for a conveyor system that I am working on.

I have an output array from a captured screen with pixels (list). the output looks like this:
[5 7 4 3]
[7 4 1 2]
[5 4 7 2]
[7 6 2 1]

I need to know how can I solve this by doing the following:

[5 7 4 3]
[7 4 1 2]
[5 4 7 2]
[1 7 6 2]
the bottom row has moved to the right: lining up the 2
the catch is that it can only move in a line (vertical and horizontal), so you can only move the col up or down and the row left to right.
and how can I get the mouse to interact with this?

# Here is my code:
import cv2
import numpy as np
import pyautogui
from PIL import ImageGrab, Image




while True:
    # Screen Capture realtime
    screenshot = ImageGrab.grab(bbox=(1158, 594, 1891, 1332))
    screenshot = np.array(screenshot)
    screenshot = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)

    img = screenshot
    rows, cols, _ = img.shape

# Creating the board
    virtual_board = np.zeros((rows, cols, 3), dtype = np.uint8)
    board_array = np.zeros((8, 8), dtype = int)

# Detecting the board
    screenshot = cv2.rectangle(screenshot, (0, 0), (732, 736), (255, 255, 255), 3)
    board_color = np.array([255, 255, 255])
    board_mask = cv2.inRange(img, board_color, board_color)
    contours, _ = cv2.findContours(board_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse = True)
    cnt = contours[0]
    (board_x, board_y, board_w, board_h) = cv2.boundingRect(cnt)
    cv2.drawContours(img, [cnt], -1, (0, 255, 0), 2)
    cv2.drawContours(virtual_board, [cnt], -1, (0, 255, 0), 0)

# Detecting boxes
    boxes = {"1": [180, 180, 180], # White Rectangle
             "2": [255, 72, 255],  # Purple Round
             "3": [213, 124, 255],  # Pink Square
             "4": [30, 137, 255],  # Orange Oval
             "5": [80, 116, 163],  # Bronze Triangle
             "6": [255, 199, 64],  # Teal Rectangle
             "7": [56, 255, 255],  # Yellow Sharp Oval
             "8": [29, 255, 154],  # Green EyeDrop
             "9": [164, 59, 108],  # Blue Square
             "10": [27, 28, 143]}  # Red Harts

    match_list = [(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]


# Creating mask for each boxes
    for key in boxes:
        bgr_color = boxes[key]
        bgr_color = np.array(bgr_color)
        mask = cv2.inRange(img, bgr_color, bgr_color)
        contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        for cnt in contours:
            (x, y, w, h) = cv2.boundingRect(cnt)
            cv2.rectangle(virtual_board, (x, y), (x + w, y + h),
                          (0, 0, 255), 2)

         # Creating cells of board
            block_width = int(board_w / 8)
            block_height = int(board_h / 8)

            for board_row in range(8):
                for board_col in range(8):
                    block_x = block_width * board_col
                    block_y = block_height * board_row

                    cv2.rectangle(virtual_board, (board_x + block_x, board_y + block_y),
                                  (board_x + block_x + block_width, board_y + block_y + block_height),
                                  (255, 255, 255), 1)

                    # Check if boxes is inside the cells
                    if board_x + block_x <= x < board_x + block_x + block_width and \
                            board_y + block_y <= y < board_y + block_y + block_height:
                        board_array[board_row][board_col] = key
Reply
#2
anyone that can guide me on where I can get more info on doing the above?

Thanx
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to make the movement humanized isv 4 1,551 Jul-29-2022, 07:14 PM
Last Post: XavierPlatinum
  How to get continuous movement whilst using State Machine cjoe1993 2 1,818 Dec-10-2020, 06:36 AM
Last Post: cjoe1993
  Moving mouse so that games can detect movement SheeppOSU 2 1,943 Jun-09-2020, 07:23 PM
Last Post: SheeppOSU
  Count to movement according to the time pressed button noartist 1 2,512 Feb-27-2019, 01:33 PM
Last Post: noartist
  movement in a zigzag in a 2d array ShakeDat53 1 2,850 Aug-17-2018, 08:22 PM
Last Post: ichabod801
  Can't change Right to left id spawning/ movement to top to bottom Kingrocket10 3 3,801 Dec-14-2017, 11:05 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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