0

I am attempting to create a model that can recognize green circles or green rectangular arrows as shown in the "image".

I figured I would need to make my own classifier and I am using Cascade Trainer to accomplish this. (See repo for the classification images and .xml file.)

Complete code and supporting files here: https://github.com/ThePieMonster/Computer-Vision

# Analyze Screenshots
print("Analyze Screenshots")
img = cv2.imread('Data/image.png')
classifier_path = 'Data/train/classifier/cascade.xml'

img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

print("- load classifier")
cascade = cv2.CascadeClassifier(classifier_path)
print("- detect objects")
objects = cascade.detectMultiScale(image=img_rgb, scaleFactor=1.10, minNeighbors=3)
print("- draw rectangle around objects")
for(x,y,w,h) in objects:
    # cv2.rectangle(<image>, (x,y), (x+w,y+h), <rectangle rgb color>, <rectangle thickness>)
    img = cv2.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2)

cv2.imshow('img', img)
cv2.waitKey(0)
print()

As you can see via the below image, I can't seem to get the classifier to recognize the green dots. There are about 41 green dots in the image and I am hoping to spot them all, currently I have a few red dots spotted and some random map squares. Any help is much appreciated!

enter image description here

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Pie
  • 856
  • 4
  • 12
  • 33
  • Do you need deep learning for this? Think about separating the image into RGB channels, and using clustering algorithms (like DBSCAN) to find clusters of red or green pixels. When the dots overlap, you can look into the *distance transform* and *watershed* algorithms to separate the dots. https://docs.opencv.org/4.x/d3/db4/tutorial_py_watershed.html – Michael Sohnen Aug 03 '22 at 07:32
  • please provide clean input data. the only picture in your question so far shows results but it's not exactly suitable as input data. -- your bounding boxes tell me that your training data is bad. you need to label those things a lot tighter. what image resolution do you pass into the (haar?) cascade training? – Christoph Rackwitz Aug 03 '22 at 10:36
  • @ChristophRackwitz Check the GitHub url I posted. It has a file called "image.png" that is the unedited raw image. – Pie Aug 03 '22 at 18:24
  • @ChristophRackwitz In regards to Haar, it probably is bad as I just started using it. What do you mean by labeling? Also you can view the Haar training data in the GitHub URL also. – Pie Aug 03 '22 at 18:25
  • @MichaelSohnen Interesting comments. I am unsure if deep learning would be required or not. I was informed that Haar might not be the best model type to use so looking at other models as well. – Pie Aug 03 '22 at 18:32
  • that map is HTML, or maybe something drawn on a canvas. you should approach this with "web scraping". drill into the html/js/whatever is supplying the data that is drawn there. – Christoph Rackwitz Aug 03 '22 at 18:51
  • @ChristophRackwitz It is a HTML Canvas, looking at the DevTools in Chrome it only shows canvas elements in 512px blocks but no data on the canvas itself so not sure how web scraping would work in that case but I could post another question focusing just on digging into the canvas. – Pie Aug 04 '22 at 06:15
  • well, something's drawing on those canvas elements, and it's getting that information from somewhere. I'm not saying the canvas itself still holds the information. -- apart from that, if you need to approach this with image processing and such, you really should consider some simple thresholding/cv::inRange in a suitable color space (HSV or sth). then you'll have connected components or contours. that'll make things easier (no multiscale cascade classifier). you could feed the results into a simple neural network easily. – Christoph Rackwitz Aug 04 '22 at 08:58
  • @ChristophRackwitz do you have a way to reach you via instant messaging? – Pie Aug 06 '22 at 23:10
  • I hang out in #opencv on libera, the "official" irc channel for OpenCV. do not *expect* any brain cycles. my attention is not an omnivore. – Christoph Rackwitz Aug 06 '22 at 23:19

0 Answers0