BIN Image from device

Hello.

We use node-red to controll a Vision Inspection System. Works very well but one thing i miss.

I want get directly via TCP the image from the camera.
From the inspection system manual:

I demo code written in C:

Any ideas how I could achieve that?

Thanks,
Christian

I'll have a go at this shortly - if no one else jumps in (just about to do school run)

@schnello

Reading the c# code, this will get you close, it will likely need some tweaking, and you will need to install the buffer parser node (this is my first time using it :smile:)

From what you have pasted - it uses ascii to detail the size of the image (which is a shame) - unless there is another way in the parser (@Steve-Mcl?)

Anyway, it should get you fairly close.

You may need to also install

To utilise the pixel data.
You will need to also provide the IP/PORT of the server.

Have fun!

[{"id":"e218090699024d27","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"c266203814a68d6b","type":"tcp request","z":"e218090699024d27","name":"","server":"","port":"","out":"sit","ret":"buffer","splitc":" ","newline":"","trim":false,"tls":"","x":630,"y":185,"wires":[["62fa6fd384fd99c5"]]},{"id":"710de31313433d77","type":"inject","z":"e218090699024d27","name":"Trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":155,"y":185,"wires":[["4f2ffde5f595ccad"]]},{"id":"4f2ffde5f595ccad","type":"change","z":"e218090699024d27","name":"Trigger (TRG)","rules":[{"t":"set","p":"expectImage","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"[84,82,71]","tot":"bin"}],"action":"","property":"","from":"","to":"","reg":false,"x":375,"y":185,"wires":[["c266203814a68d6b"]]},{"id":"3f646f5147769daa","type":"change","z":"e218090699024d27","name":"Request (Last Good GIM2)","rules":[{"t":"set","p":"expectImage","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"[71,73,77,49]","tot":"bin"}],"action":"","property":"","from":"","to":"","reg":false,"x":425,"y":235,"wires":[["c266203814a68d6b"]]},{"id":"052f8f2467205cd4","type":"link out","z":"e218090699024d27","name":"Request Image","mode":"link","links":["514c2a6dc4aa3735"],"x":1030,"y":205,"wires":[],"inputLabels":["Request"],"l":true},{"id":"514c2a6dc4aa3735","type":"link in","z":"e218090699024d27","name":"Request Image","links":["052f8f2467205cd4"],"x":160,"y":235,"wires":[["3f646f5147769daa"]],"l":true},{"id":"62fa6fd384fd99c5","type":"switch","z":"e218090699024d27","name":"Expext Image?","property":"expectImage","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":805,"y":185,"wires":[["7e24bb14c686588c"],["052f8f2467205cd4"]]},{"id":"7e24bb14c686588c","type":"link out","z":"e218090699024d27","name":"Process Image","mode":"link","links":["3651691b95fc244d"],"x":1030,"y":165,"wires":[],"l":true},{"id":"3651691b95fc244d","type":"link in","z":"e218090699024d27","name":"Prcoess Image","links":["7e24bb14c686588c"],"x":160,"y":370,"wires":[["825bd2749d69c9ee"]],"l":true},{"id":"ff14af022f8808cb","type":"inject","z":"e218090699024d27","name":"Test Data (10*10) size","props":[{"p":"payload"},{"p":"JustSoWeHaveACopy","v":"GIMP001001000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[71,73,77,80,48,48,49,48,48,49,48,48,48,49,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48]","payloadType":"bin","x":195,"y":440,"wires":[["825bd2749d69c9ee"]]},{"id":"825bd2749d69c9ee","type":"buffer-parser","z":"e218090699024d27","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"ascii","name":"passFail","offset":3,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"ascii","name":"errorCode","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"ascii","name":"imageType","offset":5,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"ascii","name":"imageResult","offset":6,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"ascii","name":"rows","offset":7,"length":4,"offsetbit":0,"scale":"1","mask":""},{"type":"ascii","name":"cols","offset":11,"length":4,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":375,"y":370,"wires":[["f341d24989f463da"]]},{"id":"f341d24989f463da","type":"change","z":"e218090699024d27","name":"Parse Interger ASCII","rules":[{"t":"set","p":"payload.rows","pt":"msg","to":"$number(payload.rows)","tot":"jsonata"},{"t":"set","p":"payload.cols","pt":"msg","to":"$number(payload.cols)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":605,"y":370,"wires":[["2a1702abdb5c5619"]]},{"id":"2a1702abdb5c5619","type":"function","z":"e218090699024d27","name":"Extract Image Data","func":"const imageData = msg.buffer.slice(15,msg.payload.rows*msg.payload.cols)\nmsg.payload.imageData = imageData\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":845,"y":370,"wires":[["0da54066cf789b20"]]},{"id":"0da54066cf789b20","type":"debug","z":"e218090699024d27","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1055,"y":365,"wires":[]}]

Hey.

First: Thanks for your help. I would be happy if I could really crack the nut with help.
I try the flow and i got the image data as a buffer. But i cant read or display the image.
Error Message from the image node:
Error: Could not find MIME for Buffer

As i understand the flow does extract the image data with msg.buffer.slice(15,msg.payload.rows*msg.payload.cols)
This is the same as the c code does.

But what i guess what is missing is the creation of the image.
drawBmp(imgStream, col, row);

I dont know what drawBmp is. It looks like this function create with the buffer + row count + col count the final image.

Edit: Found this one. Will try if i can create a image with this informations.

Thanks,
Christian

That code should pack the pixel data into a correct BIMTAP file...
you should in theory be able to then pass the result into the image view.

Sadly, I'm not an image file / specification expert :laughing:

EDIT
Raw Pixel data isn't enough sometimes.
The rows, cols may only specify the size of the blob - but you also need the stride

  • How many cols, make up a scanline in the image

In .NET this is why it needs to know the pixel format - in this case it appears to be 8bppIndexed
Else you will get an image that skews for each scanline and will appear leaning towards one side

1 Like

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