How to use the Ergo Jr camera in Python?

Hello!
I’m new on the forum, please tell me if my topic exists already.
I started this year to use the poppy-ergojr for a project in class.
I didnt meet any difficulties in using the motors for all of the moving functionalities, but i need to set the camera as ‘dummy’ before using the robot. As i would like to use the camera to recognize a face or read a qr code, how or where can i set the camera?
I used ‘poppy-configure ergo-jr m1’ to configure the motors, but dont know how to configure the camera.

Thanks for reading

Bonjour!
Je suis nouveau sur le forum, je vous prie de m’indiquer si mon sujet existe déjà.
J’ai commencé à utiliser le poppy ergo jr cette année pour un projet en classe.
Je n’ai pas rencontré de difficulté en utilisant les moteurs pour toutes les fonctionalitées de déplacement, mais j’ai besoin de mettre la caméra en ‘dummy’ avant d’utiliser le robot. Etant donné que j’aimerai utiliser la caméra pour reconnaitre un visage ou lire un qr code, comment ou où puis je configurer la camera?
J’ai utilisé ‘poppy-configure ergo-jr m1’ pour configurer les moteurs, mais je en sais pas comment configurer le moteur.

Merci de votre attention

Hello and welcome !

Every sensors defined on the robot configuration file is needed to start the robot. As the camera is a sensor, it is needed to start the robot. To be able to start the robot even if the camera is not wired, we added another argument on the Robot class camera, which can be set to `dummy’ to spoof a fake camera sensor.

If you have a working camera (Raspberry Pi camera or any USB camera) wired on the robot you don’t need to worry about camera='dummy' ; the camera will be started with the robot.

You have access to the camera image from robot.camera.frame:

poppy = PoppyErgoJr()
img = poppy.camera.frame

To look at markers, there is the MarkerDetector Primitive: which is attached on the PoppyErgoJr:

detected_markers = poppy.marker_detector.markers

You can use OpenCV 3 to do whatever you want from the camera.

Hello!

Sorry for my delayed, i’m not working alone on the PoppyErgoJr and i was overwhelmed when i got it.
First of all thanks for your answer, it gave me the way to solve it.
I tested with another raspberry pi camera and it didnt detect it. But poppy detected my webcam usb wired.
I talked to some people working on poppy about this problem, and they explained to me that the raspberry pi 2 cant detect the rasp camera, only the pi 3 can.

Anyways thanks for the links, i used a lot the camera to recognize somebody and it worked.

Problem Solved.

The Raspberry Pi camera works on Pi 1, 2 & 3. You have to avoid to plug in if the Raspberry is running, you can cause short-circuits and break the camera.

Sorry Sir,

I am new from this forum. I am trying to use the Camera to do something like item detection.

I know I have to use the above python code but I don’t know how to run the above code in Jupyter.

Also, i have a silly question… Should I download something from the OpenCv website?

Sorry for bothering and looking forward to see your reply. Thanks

Hello chunglb!
With import you normally do not have to download it.
Try these two blocks in jupyter:

from poppy.creatures import PoppyErgoJr
import cv2
import matplotlib.pyplot as plt
import time

poppy=PoppyErgoJr()
time.sleep(0.5)
image=poppy.camera.frame
plt.imshow(image)

If it works you should see a picture. I hope it can help you.

Thanks very much! I am able to run some script in notebook. Now I am trying to work out some tasks such as Pick up things through Detection. =)

Thanks again.

Hi,

I was trying out the “Discover your Ergo Jr” notebook, and I came across this part when you get to see the image from the camera:

img = poppy.camera.frame
imshow(img)

I get the following error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
in ()
1
2 img = poppy.camera.frame
----> 3 imshow(img)

NameError: name 'imshow' is not defined

I tried out your code (importing matplotlib.pyplot) and the error is gone, but what I get is:

<matplotlib.image.AxesImage at 0x63ff77f0>

And not an actual image. Do you know what it could be?

Thank you in advance

Actually it was only that I forgot to run the line at the beginning:

%pylab inline