-1

I try detect Aruco codes on images. I'm working at Jupyter Notebook in Docker, so I working with images, not videos and do not have access to some functions (for example cv2.imshow('QueryImage', QueryImg) )

Based on code: https://github.com/kyle-bersani/opencv-examples/blob/master/SimpleMarkerDetection/DetectMarkersAndPrint.py

I prepare this script:

import numpy
import cv2
import cv2.aruco as aruco
from matplotlib import pyplot as plt

im = cv2.imread('ar3.jpg')

ARUCO_PARAMETERS = aruco.DetectorParameters_create()
# OLD:
# ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_6X6_1000)
# NEW
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)

plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 

im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
corners, ids, rejectedImgPoints = aruco.detectMarkers(im, ARUCO_DICT, parameters=ARUCO_PARAMETERS)

if ids is not None and len(ids) == 5:
    for i, corner in zip(ids, corners):
            print('ID: {}; Corners: {}'.format(i, corner))

    im = aruco.drawDetectedMarkers(im, corners, borderColor=(0, 0, 255))
else:
    print("NONE")
plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 

And use simple image with markers:

enter image description here

But my code do not see these markers.

Problem is with code, image or markers? Do You have any idea?

Update: I generate markers using this code:

import cv2
import cv2.aruco as aruco

# Create gridboard, which is a set of Aruco markers
# the following call gets a board of markers 5 wide X 7 tall
gridboard = aruco.GridBoard_create(
        markersX=5, 
        markersY=7, 
        markerLength=0.04, 
        markerSeparation=0.01, 
        dictionary=aruco.Dictionary_get(aruco.DICT_5X5_1000))

# Create an image from the gridboard
img = gridboard.draw(outSize=(988, 1400))
cv2.imwrite("test_gridboard.jpg", img)

And I get this image: enter image description here Next I copy markers from this image and paste it into image (as You see at 1st image). Moreover, I replaced Dictionaries:

# OLD:
# ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_6X6_1000)
# NEW
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)

But this code still can't detect markers. Moreover any app from Google Play can't detect them too. I test this image with apps:

sosnus
  • 968
  • 10
  • 28
  • 2
    the outer two are broken because the "quiet zone" is mandatory. – Christoph Rackwitz Dec 17 '21 at 23:00
  • 1
    by the way... your codes are 5x5. did you notice? – Christoph Rackwitz Dec 18 '21 at 11:14
  • @ChristophRackwitz thank You for information, I updated my post. Maybe You have any idea what I can do now? – sosnus Dec 21 '21 at 09:36
  • 1
    if you lack imshow, use this `from google.colab.patches import cv_imshow` -- since you fixed the 6x6/5x5 issue, at least two markers should to be found -- you should think hard about this line: `if ids is not None and len(ids) == 5:` and what happens when that _is not_ the case. – Christoph Rackwitz Dec 21 '21 at 11:34
  • Thank You @ChristophRackwitz , now everything working ;) I don't know why I forgot edit line with 'if' – sosnus Dec 22 '21 at 23:28

1 Answers1

0

Now everything working, code after improvements:

import numpy
import cv2
import cv2.aruco as aruco
from matplotlib import pyplot as plt

im = cv2.imread('2-03.png')
# im = cv2.imread('1-07.jpg')

ARUCO_PARAMETERS = aruco.DetectorParameters_create()
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_5X5_1000)

plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 

im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
corners, ids, rejectedImgPoints = aruco.detectMarkers(im, ARUCO_DICT, parameters=ARUCO_PARAMETERS)

if ids is not None:
    print('detected: {}'.format(len(ids)))
    # for i, corner in zip(ids, corners):
            # print('ID: {}; Corners: {}'.format(i, corner))

    im = aruco.drawDetectedMarkers(im, corners, borderColor=(255, 0, 0))
else:
    print("NONE")
plt.figure(figsize = (20,20))
imgplot = plt.imshow(im, interpolation='nearest')
plt.show() 
sosnus
  • 968
  • 10
  • 28