Skip to content

Instantly share code, notes, and snippets.

@tommyjtl
Created May 25, 2016 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyjtl/b55a6c541f8244bae6a0aed111605928 to your computer and use it in GitHub Desktop.
Save tommyjtl/b55a6c541f8244bae6a0aed111605928 to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
import aruco
if __name__ == '__main__':
# load board and camera parameters
boardconfig = aruco.BoardConfiguration("chessboardinfo_small_meters.yml")
camparam = aruco.CameraParameters()
camparam.readFromXMLFile("dfk72_6mm_param2.yml")
# create detector and set parameters
detector = aruco.BoardDetector()
detector.setParams(boardconfig, camparam)
# set minimum marker size for detection
markerdetector = detector.getMarkerDetector()
markerdetector.setMinMaxSize(0.01)
# load frame
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FPS, 24)
# load video
# cap = cv2.VideoCapture("chessboard.mp4")
ret, frame = cap.read()
if not ret:
print "can't open video!"
exit(-1)
while ret:
likelihood = detector.detect_mat(frame)
markers = markerdetector.detect(frame, camparam)
if likelihood > 0.05:
# get board and draw it
board = detector.getDetectedBoard()
board.draw(frame, np.array([255, 255, 255]), 2)
print "detected ids: ", ", ".join(str(m.id) for m in board)
# show frame
cv2.imshow("frame", frame)
cv2.waitKey(100)
# read next frame
ret, frame = cap.read()
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment