I'm building a robot that needs to detect the position and rotation of multiple trained objects from a single image. For this I'm using my Raspberry Pi 3B with Raspberry OS 64-Bit.

I tried Localizer which does exactly what I need. But the Pi just crashes and never recovers.

Now I'm looking for a lightweight solution that my Pi can cope with. I only need to detect objects in a single image so it doesn't need to run in real time. (Though it would be nice if it was fast.)

There's a lot out there about object detection in general but nothing helpful about detecting the rotation of an object.

I've seen that you can use cv2.minAreaRect but that is useless because you only know the angle between 0-90 degrees. I also don't what to use cv2.HoughLines to determine the angle.

In many ways I would rather train the angle like you do for Localizer.

Any ideas or suggestions on how I could achieve rotation detection for multiple trained objects?

  • 1
    The question is not Pi specific, so it is off-topic here.
    – Vadim
    Mar 29, 2023 at 14:58

1 Answer 1


Not really a Pi problem, more a machine learning problem. It breaks down to recognising an image rotated in three dimensions. In which case you need a lot of training imagery. Let’s suppose you can use synthetic imagery and that the shape is 3D polygon, a cube will do. Then using Wolfram Mathematica you can generate thousands of rotated images of the cube. Use those as training set for a neural network, MobileNet may be a suitable architecture. Mathematica may be able to train the net for you. Train the net to recognise the rotation of the cube. Then test the net against real imagery. If it works great. If not then try training against multiple 3D shapes of varying sizes, rotations and maybe shading the surfaces of the polygon. Mathematica should handle that for you.

If you want to do object detection then you’ll need to embed the images into another surrounding image, and use something like YOLO to do the detection.

Have fun, sounds like an interesting problem. Training does take a lot of time though, especially on a Pi.

Having looked at the Git repo, I’m not surprised it won’t run on your Pi. It’s a very potent bit of code written using TensorFlow 2, which is difficult to install on RPi (see TensorFlow 2 on Raspberry Pi). You might be able to install the library by first training it on a larger platform ideally with a GPU, and then moving it on to a RPi.

The moral is: always read the repo’s README. Just because it’s easy to install doesn’t mean it’s simple software.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.