Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image as input #33

Open
anhtuduong opened this issue Nov 15, 2023 · 1 comment
Open

Image as input #33

anhtuduong opened this issue Nov 15, 2023 · 1 comment
Assignees

Comments

@anhtuduong
Copy link
Owner

Steps for Simple Image-Based Analysis:

1. Preprocessing:

  • Obtain a clear outline image of the Lego castle with distinct shapes representing each block level. Ensure the outline is well-defined and easily distinguishable.

2. Block Detection:

  • Divide the image into sections corresponding to different block levels or distinct parts of the castle (e.g., the 5x1 block, 3x1 block, 1x1 block).
  • Define criteria or thresholds to detect each block's outline by recognizing patterns or shapes that represent individual Lego blocks.

3. Matching Algorithm:

  • Develop a matching algorithm to fit the detected outlines to predefined shapes representing Lego blocks (e.g., rectangles for blocks of different sizes).
  • Use geometric transformations (like rotation, translation, scaling) to match the detected outlines to the predefined block shapes.

4. Hierarchical Assembly Interpretation:

  • Based on the matched shapes and their positions, infer the hierarchical structure of the castle.
  • Define rules or algorithms to interpret the relationships between detected block outlines to determine their hierarchical assembly order (e.g., bottom-up approach).

5. Planning Robotic Actions:

  • Translate the interpreted hierarchical structure into actionable instructions for the robot arm.
  • Generate a sequence of pick-and-place actions based on the interpreted assembly order and block positions.

6. Testing and Validation:

  • Test the algorithm with various castle outlines to verify its accuracy and robustness in correctly identifying the block levels and their relationships.

7. Iterative Refinement:

  • Refine the algorithm based on testing results and edge cases encountered during analysis to improve accuracy and reliability.

Example Approach:

For instance, if the outline represents a 3-level castle with a 5x1, 3x1, and 1x1 block:

  • Divide the outline into segments corresponding to the expected blocks.
  • Develop an algorithm that compares these segments with predefined shapes and sizes of Lego blocks.
  • By assessing how well the segments fit the predefined block shapes, determine the probable order and orientation of these blocks within the castle structure.

Considerations:

  • Algorithmic Precision: This approach heavily relies on the accuracy of outline detection and the matching algorithm's precision. Any noise or deviations in the outline might affect the accuracy of block recognition.
  • Scalability and Adaptability: Ensure the algorithm can handle variations in block arrangements and shapes, as well as different castle configurations.

While this method aims for precision without machine learning or 3D understanding, it requires robust image processing and shape-matching algorithms to accurately interpret the outline and infer the assembly sequence. Testing with various outlines and refining the algorithm iteratively will be crucial to achieving reliable results.

@anhtuduong anhtuduong self-assigned this Nov 15, 2023
@anhtuduong
Copy link
Owner Author

anhtuduong commented Nov 23, 2023

Template matching:

  • Create for each block sample a template image. Consider 2 version: first one is the full block, second is the cut out of the top connector.
  • Apply template matching using OpenCV. Consider Alpha-Dependent Template Matching and Multi-scale Template Matching.
  • Using width and height info result to calculate the floor of the construct.
  • Using the block X1-Y1-Z2 as a core to calculate other references (eg: 4 blocks X1-Y1-Z2 at the same floor can be 1 block X1-Y4-Z2)

References:
https://docs.opencv.org/3.4/d4/dc6/tutorial_py_template_matching.html
https://pyimagesearch.com/2015/01/26/multi-scale-template-matching-using-python-opencv/
https://docs.opencv.org/4.x/dc/dc3/tutorial_py_matcher.html
https://stackoverflow.com/questions/4761940/opencv-template-matching-and-transparency
https://answers.opencv.org/question/16535/alpha-dependent-template-matching/
https://stackoverflow.com/questions/4761940/opencv-template-matching-and-transparency
opencv/opencv#4837
https://stackoverflow.com/questions/12139381/alpha-dependent-template-matching
https://stackoverflow.com/questions/65945434/template-matching-with-python-3-9-1-opencv-python-4-5-1-48-and-mask-transparen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant