Code Monkey home page Code Monkey logo

Comments (5)

christian-rauch avatar christian-rauch commented on August 28, 2024

I adapted your script to use OpenCV's VideoCapture class:

#!/usr/bin/env python3
import apriltag
import cv2


if __name__ == "__main__":
    cam = cv2.VideoCapture()
    if not cam.isOpened():
        exit()

    detector = apriltag.apriltag(family='tag36h11')

    count = 0

    while True:
        _, image = cam.read()
        cv2.imshow("image", image)
        cv2.waitKey(1)

        # print(f'Image {count}')
        count += 1

        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        dets = detector.detect(gray)
        print(f"image {count}, detections", len(dets))
        if len(dets) > 0:
            print(f"detections", dets)

With the "Tag36h11" from https://april.eecs.umich.edu/media/apriltag/tagformats_web.png moving in and out of the camera I get a log like:

image 38, detections 0
image 39, detections 0
image 40, detections 0
image 41, detections 0
image 42, detections 1
detections ({'hamming': 1, 'margin': 95.90980529785156, 'id': 0, 'center': array([217.63509135, 132.08676829]), 'lb-rb-rt-lt': array([[167.09477234, 163.29779053],
       [252.62365723, 179.94235229],
       [266.43988037, 101.9475174 ],
       [183.34217834,  85.18266296]])},)
image 43, detections 1
detections ({'hamming': 0, 'margin': 105.45146179199219, 'id': 0, 'center': array([223.41219345, 125.66384523]), 'lb-rb-rt-lt': array([[171.00808716, 157.98808289],
       [259.49859619, 175.00976562],
       [274.39813232,  94.21437073],
       [187.78811646,  76.95012665]])},)
image 44, detections 1
detections ({'hamming': 0, 'margin': 107.93148040771484, 'id': 0, 'center': array([227.28037937, 119.98327687]), 'lb-rb-rt-lt': array([[173.24375916, 153.52482605],
       [264.44946289, 171.06555176],
       [279.59329224,  87.51166534],
       [190.35250854,  69.2325058 ]])},)
[...]
image 74, detections 1
detections ({'hamming': 0, 'margin': 109.63236236572266, 'id': 0, 'center': array([186.29173532, 141.22647609]), 'lb-rb-rt-lt': array([[125.28643799, 190.19546509],
       [235.91940308, 200.60371399],
       [246.70794678,  92.73034668],
       [136.07653809,  81.14628601]])},)
image 75, detections 1
detections ({'hamming': 0, 'margin': 103.26177215576172, 'id': 0, 'center': array([178.18746309, 147.52838709]), 'lb-rb-rt-lt': array([[119.40704346, 196.05543518],
       [225.92948914, 205.7492218 ],
       [235.50740051, 100.20706177],
       [130.6658783 ,  89.57637787]])},)
image 76, detections 0
image 77, detections 0
image 78, detections 0
image 79, detections 0
image 80, detections 0
image 81, detections 0

For me, the Python bindings work even when the detections disappear. Are you seeing this issue only on the Raspberry Pi? Can you reproduce this with my adapted script on a different PC?

from apriltag.

nlbutts avatar nlbutts commented on August 28, 2024

The python bindings worked fine with OpenCV or Pillow. But when I started a picamera2 capture, I would always get the error with spinning up threads. Although it did seem to process one frame, but the second frame would throw this error message. I write a small shared library that made the calls to the apriltag library and then used ctypes to expose the interface to my new shared library. That worked fine. I dug through the apriltag python interface, I don't see why it would fail to spin up the threads. When the FRC session is done, I might take a deeper look into this. Really weird.

from apriltag.

christian-rauch avatar christian-rauch commented on August 28, 2024

I can reproduce this now. However, I am sure this has nothing to do with the threads, but rather with something setting errno to EAGAIN.

If I add something like perror("ERR"); at the beginning of apriltag_detect, then this will already print No such file or directory for the first image (Image 0) and Resource temporarily unavailable for the next image (Image 1) without actually running any detection. So I would assume that the errno is set internally by something in capture_array().

You can work around this by printing something right after capture_array(), e.g.:

    img1 = picam2.capture_array()
    print("")

will reset the errno and thus print ERR: Success.

Maybe just resetting the errno at the beginning of apriltag_detect would be a good way to make sure that we only consider errnos generated from function calls inside apriltag_detect. But I also think that picamera2 should do better error checking.

from apriltag.

christian-rauch avatar christian-rauch commented on August 28, 2024

@nlbutts Can you check if #323 fixes your issue?

from apriltag.

nlbutts avatar nlbutts commented on August 28, 2024

That fixed the problem. So did the print("").

from apriltag.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.