Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work with pi camer? #3

Closed
cozmo14047 opened this issue Apr 21, 2024 · 9 comments
Closed

Work with pi camer? #3

cozmo14047 opened this issue Apr 21, 2024 · 9 comments

Comments

@cozmo14047
Copy link

Hi there does this work with araspberry pi also this uses obicos api to ai detect ont he camera stream right.
Manu thanks

@nvtkaszpir
Copy link
Owner

can you rephrase your question please?
or explain what you have and what you want to do, and which subdirectory are you referring to?

@cozmo14047
Copy link
Author

Hi there sorry, i didint realise it was in just 3d printing direcory, for the obico one i see you say esp but nothing about raspberry pi. i just wanted to know if its compatable with a raspberry pi many thanks

@nvtkaszpir
Copy link
Owner

You would have to expose rpi camera snapshot as static image over the web (there are many ways how to do it), that would be the best option.

Using camera device directly would require more code adjustments (using python picamera), but because it would require using camera directly via python it may interfere with other tools - so I'm not going to do it.

@nvtkaszpir
Copy link
Owner

I think the easiest would be to run some process which would expose rpi camera as snapshot and then use that endpoint to fetch image.
Short search gives that https://github.com/signag/raspi-cam-srv should work with https://<server>:<port>/photo_feed

@nvtkaszpir
Copy link
Owner

if you mean you want to use ml_api on the rpi and do detections on the image fetched directly from the camera, then no, right now this is not possible and it would require much more work:

  • add code to fetch image from camera using picamera python lib
  • compile code for rpi (arm and arm64 platfroms) which means fighting a lot fo dependencies
  • compute on rpi would be pretty slow and probably would take seconds to do a detection on full screen image.

For now this is just too much work so I'm not planning to do it.
Closing.

@nvtkaszpir
Copy link
Owner

try https://github.com/nvtkaszpir/3d-print/tree/main/picamera-web as an endpoint exposing pi camera image over the web

@cozmo14047
Copy link
Author

Thank you. I didint think it would work with the pi thats why i asked

@nvtkaszpir
Copy link
Owner

nvtkaszpir commented May 3, 2024

what I tested:

Running picamera-web on rpi and obico and scripts on another host

Testing it directly on rpi4 on 64bit Debian 12, where 192.168.1.50 is the IP address of the raspberry pi:

  • run all above on the rpi 4 - this way it would run obico and camera exposing service on the same device

  • it should work but will be slow

  • install docker and obico ml-api container (notice it fetches 3GB so it will take time)

     sudo docker run -it -p 3333:3333 quay.io/kaszpir/ml_api:812a05b7-arm64 gunicorn --bind 0.0.0.0:3333 --workers 1 wsgi --preload -e DARKNET_PATH=/darknet
  • in another terminal, fetch scripts and run picamera-web

     cd src
     git clone https://github.com/nvtkaszpir/3d-print.git
     cd 3d-print/picamera-web
     make web
  • in another terminal

     cd src/3d-print/obico-ml-api-only
     python3 draw_detections.py --api https://127.0.0.1:3333 https://192.168.1.50:8090/ --show
  • result:

     pi@hormex:~/src/3d-print/obico-ml-api-only $ Error: no "view" rule for type "image/png" passed its test case
            (for more information, add "--debug=1" on the command line)
     python3 draw_detections.py --api https://127.0.0.1:3333 https://192.168.1.50:8090/
     INFO:root:treshold=0.2
     INFO:root:api=https://127.0.0.1:3333
     INFO:root:ignore=[]
     INFO:root:show=False
     INFO:root:img_url=https://192.168.1.50:8090/
     INFO:root:saveimg=None
     INFO:root:savedet=None
     INFO:root:ignore_list: []
     DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 192.168.1.50:8090
     DEBUG:urllib3.connectionpool:https://192.168.1.50:8090 "GET / HTTP/1.1" 200 54196
     DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1:3333
     DEBUG:urllib3.connectionpool:https://127.0.0.1:3333 "GET /p/?img=http%3A%2F%2F192.168.1.50%3A8090%2F&ignore=%5B%5D HTTP/1.1" 200 74
     INFO:root:detections: [["failure", 0.119, [326.0, 133.0, 264.0, 326.0]]]
     INFO:root:ignored: []
     
    

it detected failed area with confidence 0.119 (11.9%) - mainly because I have there some dummy spaghetti in front of camera :)

So it works but is slow.

@nvtkaszpir
Copy link
Owner

also, obico-ml-api-only was not tested with video streams (I doudb it would work), so you would have to make a new service to expose single camera image from a stream so that obico ml api could fetch it and process it.
For such scenarios I suggest just using official obico.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants