예제 #1
0
 def __init__(self, nMarkers=8, markerSize=3, markerLength=0.012, markerSeparation=0.003, randomSeed=10, size=(0, 0)):
     self.aruco_dict = aruco.custom_dictionary(nMarkers, markerSize, randomSeed)
     if size == (0, 0):
         self.size = (1, nMarkers)
         self.board = aruco.GridBoard_create(1, nMarkers, markerLength, markerSeparation, self.aruco_dict)
     else:
         self.size = size
         self.board = aruco.GridBoard_create(size[0], size[1], markerLength, markerSeparation, self.aruco_dict)
 def __init__(self):
     self.dictionary = aruco.custom_dictionary(10, 6)
     self.pose_world = Pose()
     # self.pose_tello = Pose()
     # self.pose_world_to_tello = Pose()
     self.marker_size_world = 0.2
     # self.marker_size_tello = 0.02
     self.image_out = np.zeros((1, 1), dtype=np.float32)
     self.is_detected = False
예제 #3
0
def get_dictionary():
    path = os.path.join('assets', 'dictByteList.json')
    try:
        if not os.path.isfile(path):
            raise FileNotFoundError()
        storage = cv2.FileStorage(path, cv2.FILE_STORAGE_READ)
        dictionary = aruco.custom_dictionary(1000, 5)
        dictionary.markerSize = int(storage.getNode("markerSize").real())
        dictionary.maxCorrectionBits = int(storage.getNode("maxCorrectionBits").real())
        dictionary.bytesList = storage.getNode("bytesList").mat()
        storage.release()
    except FileNotFoundError as e:
        storage = cv2.FileStorage(path, cv2.FILE_STORAGE_WRITE)
        dictionary = aruco.custom_dictionary(1000, 5)
        storage.write("markerSize", dictionary.markerSize)
        storage.write("maxCorrectionBits", dictionary.maxCorrectionBits)
        storage.write("bytesList", dictionary.bytesList)
        storage.release()
    return dictionary
예제 #4
0
 def __init__(self):
     self.url = "http://192.168.3.22:8080/?action=stream"
     self.capture = cv2.VideoCapture(self.url)
     self.dictionary = aruco.custom_dictionary(10, 6)
     self.pose_world = Pose()
     self.pose_tello = Pose()
     self.pose_world_to_tello = Pose()
     self.marker_size_world = 0.04
     self.marker_size_tello = 0.02
     self.image = np.zeros((1, 1), dtype=np.float32)
     self.is_detected = False
예제 #5
0
    def __init__(self):
        # Create custom dictionary (# markers, # bits)
        self.arucoDict = aruco.custom_dictionary(17, 3)

        # Calibration 
        self.mtx = None
        self.dist = None

        # Calibration directories
        self.calibrationDir = 'calibrationImgs/'
        self.imgExtension = '.jpg'
예제 #6
0
def get_dictionary():
    aruco_dict = aruco.custom_dictionary(0, 5, 1)
    aruco_dict.bytesList = np.empty(shape=(11, 4, 4), dtype=np.uint8)

    # LEG 1
    mybits = np.array([
        [1, 1, 1, 1, 1],
        [1, 1, 0, 0, 1],
        [1, 1, 1, 1, 1],
        [0, 0, 1, 0, 1],
        [0, 0, 1, 0, 1]
    ], dtype=np.uint8)
    aruco_dict.bytesList[0] = aruco.Dictionary_getByteListFromBits(mybits)

    # LEG 2
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [0, 0, 1, 1, 0],
        [1, 1, 1, 0, 1]
    ], dtype=np.uint8)
    aruco_dict.bytesList[1] = aruco.Dictionary_getByteListFromBits(mybits)

    # LEG 3
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [1, 0, 1, 1, 0],
        [1, 0, 1, 1, 0]
    ], dtype=np.uint8)
    aruco_dict.bytesList[2] = aruco.Dictionary_getByteListFromBits(mybits)

    # LEG 4
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [0, 1, 1, 1, 1],
        [1, 0, 1, 0, 0]
    ], dtype=np.uint8)
    aruco_dict.bytesList[3] = aruco.Dictionary_getByteListFromBits(mybits)
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [0, 1, 1, 1, 0],
        [0, 1, 1, 1, 0]
    ], dtype=np.uint8)
    aruco_dict.bytesList[4] = aruco.Dictionary_getByteListFromBits(mybits)

    # LEG 5
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [1, 0, 1, 1, 1],
        [0, 1, 1, 0, 0]
    ], dtype=np.uint8)
    aruco_dict.bytesList[5] = aruco.Dictionary_getByteListFromBits(mybits)
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [0, 0, 1, 1, 1],
        [0, 0, 1, 1, 1]
    ], dtype=np.uint8)
    aruco_dict.bytesList[6] = aruco.Dictionary_getByteListFromBits(mybits)

    # LEG 6
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [1, 1, 1, 1, 0],
        [0, 0, 1, 0, 1]
    ], dtype=np.uint8)
    aruco_dict.bytesList[7] = aruco.Dictionary_getByteListFromBits(mybits)
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [0, 0, 1, 0, 1],
        [1, 1, 1, 1, 0]
    ], dtype=np.uint8)
    aruco_dict.bytesList[8] = aruco.Dictionary_getByteListFromBits(mybits)

    #  LEG 7
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [1, 1, 1, 0, 0],
        [1, 1, 1, 0, 0]
    ], dtype=np.uint8)
    aruco_dict.bytesList[9] = aruco.Dictionary_getByteListFromBits(mybits)
    mybits = np.array([
        [1, 1, 0, 1, 1],
        [1, 1, 0, 1, 1],
        [1, 0, 1, 0, 1],
        [0, 1, 1, 0, 0],
        [1, 0, 1, 1, 1]
    ], dtype=np.uint8)
    aruco_dict.bytesList[10] = aruco.Dictionary_getByteListFromBits(mybits)

    return aruco_dict
예제 #7
0
import os
import cv2
from cv2 import aruco

aruco_dict = aruco.custom_dictionary(20, 3, 1)
cap = cv2.VideoCapture(0)

while (True):
    ret, frame = cap.read()
    corners, ids, rejectedImgPoints = aruco.detectMarkers(
        frame, aruco_dict, parameters=aruco.DetectorParameters_create())
    frame = aruco.drawDetectedMarkers(frame, corners, ids, (255, 0, 255))
    cv2.imshow('Look IDs', frame)
    # 若按下 q 鍵則離開
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
예제 #8
0
import cv2
import cv2.aruco as aruco
import math

from tkinter import *
from tkinter import filedialog

from PIL import Image, ImageTk
import matplotlib.pyplot as plt
import matplotlib.image as img

# we will not use a built-in dictionary, but we could
# aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_50)

# define an empty custom dictionary with
aruco_dict = aruco.custom_dictionary(44, 5, 1)
# add empty bytesList array to fill with 3 markers later
aruco_dict.bytesList = np.empty(shape=(44, 4, 4), dtype=np.uint8)

# add new marker(s)
mybits = np.array([[0, 1, 1, 0, 0], [1, 0, 1, 0, 0], [0, 0, 1, 0, 0],
                   [0, 0, 1, 0, 0], [1, 1, 1, 1, 1]],
                  dtype=np.uint8)
aruco_dict.bytesList[0] = aruco.Dictionary_getByteListFromBits(mybits)
mybits = np.array([[0, 1, 1, 1, 0], [1, 0, 0, 0, 1], [0, 0, 0, 1, 0],
                   [0, 0, 1, 0, 0], [1, 1, 1, 1, 1]],
                  dtype=np.uint8)
aruco_dict.bytesList[1] = aruco.Dictionary_getByteListFromBits(mybits)
mybits = np.array([[0, 1, 1, 1, 0], [1, 0, 0, 0, 1], [0, 0, 1, 1, 0],
                   [1, 0, 0, 0, 1], [0, 1, 1, 1, 0]],
                  dtype=np.uint8)
예제 #9
0
import rospy
from sensor_msgs.msg import CompressedImage
from geometry_msgs.msg import TwistStamped
from sensor_msgs.msg import Image
from sensor_msgs.msg import Imu

from cv_bridge import CvBridge, CvBridgeError
import cv2.aruco as aruco
from scipy.spatial.transform import Rotation as R
import time
import tf

HEIGHT_CUT = 200
VERBOSE = True

aruco_dict = aruco.custom_dictionary(0, 7)
aruco_dict.bytesList = np.zeros(shape=(16, 7, 4), dtype=np.uint8)

ar = np.array([[1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1],
               [0, 0, 1, 1, 0], [1, 1, 1, 0, 1]],
              dtype=np.uint8)
aruco_dict.bytesList[1] = aruco.Dictionary_getByteListFromBits(
    np.pad(ar, pad_width=1, mode='constant', constant_values=0))

ar = np.array([[1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1],
               [1, 0, 1, 1, 0], [1, 0, 1, 1, 0]],
              dtype=np.uint8)
aruco_dict.bytesList[2] = aruco.Dictionary_getByteListFromBits(
    np.pad(ar, pad_width=1, mode='constant', constant_values=0))

ar = np.array([[1, 1, 0, 1, 1], [1, 1, 0, 1, 1], [1, 0, 1, 0, 1],
예제 #10
0
# """
# JUST ONE EXECUTION IS NEEDED.
# Two png files will appear in markers directory.
# Each time you open the TWINBOT simulator, disable the aruco markers of the Girona 500 1,
# and adjust the aruco markers of the Girona 500 2 to the new ones.
# C:\Users\Usuario\Desktop\Sistemas Inteligentes UJI\Asignaturas\2o trimestre\Robótica Cooperativa\TwinbotControl\markers
# """

import cv2 as cv
import cv2.aruco as aruco

numMarkers = 2
markerSize = 4
CUSTOM_DICT = aruco.custom_dictionary(numMarkers, markerSize, 0)


def get_custom_dict():
    return CUSTOM_DICT


if __name__ == "__main__":
    pixels_per_cell = 20
    for i in range(numMarkers):
        img = aruco.drawMarker(CUSTOM_DICT, i,
                               pixels_per_cell * (markerSize + 2))
        cv.imwrite("markers/marker{:d}.png".format(i), img)
예제 #11
0
                       [[-sd / 2., sp / 2., ht]]],
                      [[[-sd / 2., -sp / 2, ht]], [[sd / 2., -sp / 2., ht]], [[sd / 2., -(sp / 2. + sd), ht]],
                       [[-sd / 2., -(sp / 2. + sd), ht]]],
                      [[[-wr / 2., sd / 2., hs - sd]], [[-wr / 2., sd / 2., hs]], [[-wr / 2., -sd / 2., hs]],
                       [[-wr / 2., -sd / 2., hs - sd]]],
                      [[[wr / 2., sd / 2., hs]], [[wr / 2., sd / 2., hs - sd]], [[wr / 2., -sd / 2., hs - sd]],
                       [[wr / 2., -sd / 2., hs]]]], dtype=np.float32)

# objPoints = np.array([[[[-sd/2., sp/2.+sd, ht]], [[sd/2., sp/2.+sd, ht]], [[sd/2., sp/2., ht]], [[-sd/2., sp/2., ht]]],
#     [[[-sd/2., -sp/2, ht]], [[sd/2., -sp/2., ht]], [[sd/2., -(sp/2.+sd), ht]], [[-sd/2., -(sp/2.+sd), ht]]]], dtype=np.float32)

cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, FRAME_W)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, FRAME_H)
cam.set(cv2.CAP_PROP_FPS, FPS)
arudict = aruco.custom_dictionary(8, 3)
logitech_cam_matrix = np.array([6.6419013281274511e+02, 0., 3.3006505461506646e+02, 0.,
                                6.6587003740196826e+02, 2.3030870519881907e+02, 0., 0., 1.])
logitech_cam_matrix = logitech_cam_matrix.reshape((3, 3))
logitech_dist_coeffs = np.array([2.0806786957819065e-01, -3.6839605435678208e-01,
                                 -1.2078578161331370e-02, 6.4294407773653481e-03,
                                 4.2723310854154123e-01])

car_board0 = aruco.Board_create(objPoints, arudict, np.arange(0, 4))
car_board1 = aruco.Board_create(objPoints, arudict, np.arange(4, 8))

while True:
    ret, frame = cam.read()
    corners, ids, rejected = aruco.detectMarkers(frame, arudict)
    corners, ids, rejected, recovered = aruco.refineDetectedMarkers(frame, car_board0, corners, ids, rejected,
                                                                    logitech_cam_matrix, logitech_dist_coeffs)
예제 #12
0
def detect_markers(img_filepath):
    # img_filepath should be a .png
    img = cv2.imread(img_filepath)

    arr = [
        [0, 0, 0, 0, 0, 0, 0],
        [0, 1, 1, 0, 1, 1, 0],
        [0, 1, 1, 0, 1, 1, 0],
        [0, 1, 0, 1, 0, 1, 0],
        [0, 0, 1, 1, 1, 0, 0],
        [0, 0, 1, 1, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
    ]
    arr_flat = []
    for a in arr:
        for b in a:
            arr_flat.append(b)
    mat = np.array(arr_flat)
    bytesList = aruco.Dictionary_getByteListFromBits(mat)
    marker_dict = aruco.custom_dictionary(1, 7)
    marker_dict.bytesList = bytesList
    # marker_dict.maxCorrectionBits = 10
    img1 = aruco.drawMarker(marker_dict, 0, 500)
    cv2.imwrite("mtest.jpg", img1)

    #parameters = aruco.DetectorParameters_create()
    # marker_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
    corners, ids, rejectedImgPoints = aruco.detectMarkers(img, marker_dict)
    print(corners)
    #IPython.embed()

    for corner_set in corners:
        #corner_set is 1, 4, 2
        corner1 = corner_set[0, 0, :]
        corner2 = corner_set[0, 1, :]
        corner3 = corner_set[0, 2, :]
        corner4 = corner_set[0, 3, :]

        corner1 = np.expand_dims(corner1, axis=1)
        corner2 = np.expand_dims(corner2, axis=1)
        corner3 = np.expand_dims(corner3, axis=1)
        corner4 = np.expand_dims(corner4, axis=1)

        axis1 = corner3 - corner1
        axis2 = corner2 - corner4

        print(axis1.shape)
        A = np.hstack((axis1, -axis2))
        #IPython.embed()
        b = corner4 - corner1

        x = np.linalg.solve(A, b)

        square_center = corner4 + x[1][0] * axis2
        red = [0, 0, 255]
        # Change one pixel
        #IPython.embed()
        x = int(round(square_center[0][0]))
        y = int(round(square_center[1][0]))
        #print(x, y)

        cv2.circle(img, (x, y), 4, red, -1)
        #img[x,y]=red

    # img = cv2.resize(img, (int(img.shape[0]/4), int(img.shape[1]/4)))
    img_with_markers = aruco.drawDetectedMarkers(img, corners)
    cv2.imwrite("btest.jpg", img_with_markers)
    cv2.imshow('image', img_with_markers)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
예제 #13
0
파일: aruco-sandbox.py 프로젝트: skella/dev
print cv2.__version__

import cv2.aruco as aruco

aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
print aruco.DICT_6X6_250

test_dict = aruco.Dictionary_create(250, 6)
print test_dict.bytesList
sys.exit()

help(aruco)
sys.exit()

test_dict = aruco.custom_dictionary(250, 6)
print test_dict.bytesList
sys.exit()

#x = aruco.custom_dictionary_from(250, 36, "/home/abe/data/vision/mip36h12.dict")
#print x

#help(aruco_dict)

nbits = 36

tail_fmt = "0" + str(8 + nbits - 8 * 5) + "b"
byte_stride = 5


def test_byte_print():
예제 #14
0
import cv2
import cv2.aruco as ar
import pickle

arudict = ar.custom_dictionary(8, 4)
with open('4x4_8_dict.pickle', 'wb') as f:
    pickle.dump((arudict.bytesList, arudict.markerSize, arudict.maxCorrectionBits), f)

print(arudict)
예제 #15
0
#fig = plt.figure()
#nx = 4
#ny = 3
#for i in range(1, nx*ny+1):
#    ax = fig.add_subplot(ny,nx, i)
#    img = aruco.drawMarker(aruco_dict,i, 700)
#    plt.imshow(img, cmap = mpl.cm.gray, interpolation = "nearest")
#    ax.axis("off")

#plt.savefig("marcadores1.pdf")
#plt.show(

# )

aruco_dict = aruco.custom_dictionary(20, 7, 2)
aruco_dict.bytesList = np.empty(shape=(20, 7, 4), dtype=np.uint8)

mybits1 = np.array(
    [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0],
     [0, 1, 0, 1, 0, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0],
     [0, 0, 0, 0, 0, 0, 0]],
    dtype=np.uint8)
aruco_dict.bytesList[0] = aruco.Dictionary_getByteListFromBits(mybits1)

mybits2 = np.array(
    [[0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 0],
     [0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 1, 0, 0], [0, 1, 0, 1, 1, 0, 0],
     [0, 0, 0, 0, 0, 0, 0]],
    dtype=np.uint8)
aruco_dict.bytesList[1] = aruco.Dictionary_getByteListFromBits(mybits2)
import numpy as np
import cv2
import cv2.aruco as ar

dict = ar.custom_dictionary(10, 5)
print dict
img = ar.drawMarker(dict, 2, 700)
cv2.imwrite("gen_marker.jpg", img)

cv2.imshow('frame', img)
cv2.waitKey(0)
cv2.destroyAllWindows()