0

I have a problem: There is a map where crystals randomly appear and I somehow need to find crystal coordinates(need only one crystal's pixel coordinate), I tried to do it by the color of a specific pixel, but after some time, the pixel shade appears and it does not find it (with axis = 2). Can anyone help I would be very grateful.Maybe some size parameter should be used as it doesn't change. (python)

import cv2
import numpy as np

im = cv2.imread('photos\\temp_3.png')

# Define the blue colour we want to find - remember OpenCV uses BGR ordering
crystal = [0,248,0]

# Get X and Y coordinates of all blue pixels
Y, X = np.where(np.all(im==crystal,axis=2))

print(X, Y)

photo examples:

enter image description here

enter image description here

enter image description here

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
subUser
  • 77
  • 1
  • 9
  • 1
    You need to try a range of colors, have a look at [this question](https://stackoverflow.com/questions/52315895/simple-method-to-extract-specific-color-range-from-an-image-in-python). Also have a look at [this answer](https://stackoverflow.com/questions/10948589/choosing-the-correct-upper-and-lower-hsv-boundaries-for-color-detection-withcv/59906154#59906154) to choose your color range – Jeru Luke Apr 07 '22 at 08:17
  • 1
    [Template matching](https://docs.opencv.org/3.4/d4/dc6/tutorial_py_template_matching.html) could be another possible approach. – Thomas Apr 07 '22 at 08:23

0 Answers0