Node-Red with OpenCV

Hi, Please can anyone tell me how to do basic image processing works(image crop, thresholding, adjust brightness, contrast) with node-red. I already connect my USB camera with RSP3 B and got the live video feed through node-red.

You may try out node-red-contrib-image-tools. It has a lot of image manipulation possibilities

3 Likes

Thanks you so much. I'll try and see

..and if you still think you need to use OpenCV in NR, well, I did write about it earlier here
It's a bit time consuming to say the least and if you are looking for using the latest versions of OpenCV, you should check the details in the documentation when installing opencv4nodejs. It takes very long time to build OpenCV from source on a RPi3, so boring. But it depends on what kind of features you are looking for

1 Like

@krambriw
Thanks for the direction you provide. I referred most of the comments on that tread. Its pretty cool. First I went through to install opencv4nodejs to RSP3 B but unfortunately I couldn't complete it because of lack of space availability on my pi. It has only 8GB card. I went through some ways to cleaning processes but it didn't work. Today I tried with all effort to install it to my ubuntu 18.04 and it installed really well.

here now I stuck in few things. How can I use my USB camera work on node-red and make live video stream. My final goal is to make line following robot. I would appreciate hearing your thoughts on this.

@krambriw Do you think Motion will do my basics to setup usb cam ? It worked for me on RSP3 B previously

I am using a similar setup with some RPis running Motion.

I have Node-RED running on another machine, where I can capture a still image using an ffmpeg from an exec node, and process the image with node-red-contrib-image-tools. Mainly reducing size and quality for use in a Telegram bot.

Here's a basic flow for that, just change IP and port of your Motion server:

[{"id":"370d8c79.3d439c","type":"exec","z":"93b1388c.f7fc4","command":"ffmpeg -i http://ip:port/ -vframes 1 -f image2 -","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"cam1","x":770,"y":180,"wires":[["480b8a7d.851f6c"],[],[]]},{"id":"480b8a7d.851f6c","type":"jimp-image","z":"93b1388c.f7fc4","name":"","data":"payload","dataType":"msg","ret":"img","parameter1":".5","parameter1Type":"num","parameter2":"","parameter2Type":"none","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","parameterCount":2,"jimpFunction":"scale","selectedJimpFunction":{"name":"scale","fn":"scale","description":"scale the image by the factor f","parameters":[{"name":"f","type":"num","required":true,"hint":"f the factor to scale the image by"},{"name":"mode","type":"resizeMode","required":false,"hint":"a scaling method (e.g. Jimp.RESIZE_BEZIER)"}]},"x":970,"y":180,"wires":[["55fb53fd.007284"]]},{"id":"55fb53fd.007284","type":"jimp-image","z":"93b1388c.f7fc4","name":"","data":"payload","dataType":"msg","ret":"buf","parameter1":"50","parameter1Type":"num","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","parameterCount":1,"jimpFunction":"quality","selectedJimpFunction":{"name":"quality","fn":"quality","description":"Set the quality of the image. Usefull for reducing size of image before calling the write function.","parameters":[{"name":"quality","type":"num","required":true,"hint":"Quality value 1 ~ 100"}]},"x":1110,"y":180,"wires":[["499e37a0.8638e8"]]},{"id":"499e37a0.8638e8","type":"debug","z":"93b1388c.f7fc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1290,"y":180,"wires":[]},{"id":"f93cbddc.ff3f68","type":"inject","z":"93b1388c.f7fc4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":580,"y":180,"wires":[["370d8c79.3d439c"]]}]
1 Like

Motion works fine also on a RPi3 with usb cameras and ip cameras. I do mostly have usb cameras myself but you cannot connect more than two cameras to each RPi. The usb bandwidth is not enough for more.

If useful for your application depends what requirements you have and what type of real time analyze you need to do. If I understand you correct, line following robot, I doubt the RPi is powerful enough for such use cases, instead I would recommend you to look at NVIDIA Jetson Nano, there are already robots designed using that platform, several examples you will find googling

Motion is ideal for a home security solution, detecting (unwanted) movements around your house. In my case I have Motion normally delivering one frame per second/camera and when movement is detected, it goes up to higher frame rates (configurable). I grab those frames and do object detections.

The object detections I currently run live (in parallel for testing purposes) are:

  • NVIDIA Jetson Nano: jetson inference engine with ssd-inception-v2 using the GPU of the device
  • Lenovo laptop w debian: YOLOv3 handled by Python
  • RPi3: Tensorflow JS Coco SSD node in Node-RED

All three are doing there job pretty well and detects objects I'm looking for (unexpected visitors of mankind type). The fastest is the GPU based Jetson, followed by the CPU based analyze in the laptop. The RPi3 is then a bit behind the others but doing fine as well. I assume a RPi4 would improve the RPi path significantly

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.