Hi,
I have a data generated from a camera feed and I would like to generate an image out of it. I'm wondering if anyone here could help me in this regard. Kindly find the file attached containing the data. The glitch is - we will have to ignore the second nibble from the 8 bit. The image format is ycbcr. So by ignoring the second nibble it will give us a grey scale image.
For instance, if the data is like this - F1 40 F1 88 F1 88 F1 88 D1 88 92 88 51 90 52 88 F1 90 after processing it should be like this - F1 F1 F1 F1 D1 92 51 52 F1
This processed data will then give a greyscale image.
I tried a lot to remove the second nibble and feed this modified data to generate an image but I couldn't succeed.
Any help in this regard will be greatly appreciated.
how does the data arrive in to node-red? As a buffer?
I suspect you mean drop even bytes (a nibble is 4 bits)
Assuming it is a buffer, then you could use a function node to loop though the src buffer and write even bytes to a new buffer ...
var src = msg.payload;
var dst = Buffer.alloc(src.length/2); //as we are removing even bytes, only need half the size
for (let i = 0; i < src.length; i++) {
dst[i] = src[i*2]; //copy even no bytes to dst buffer
}
msg.payload = dst;
return msg;
We have a team at some other place which is working on a camera module interface - ov7670. The capture.txt sent to me is from this team. So the data doesn't arrive in node-red. I have to feed it manually as of now.
Exactly. For instance, if F1 40 is an 8 bit YcbCr image data consisting 4 bits nibbles each then yes, drop the 4 bit even nibble (i.e., 40 in this case) and F1 gives us only the Y component of the image which is luminous component. 40 is CbCr which needs to be dropped. This applies to each and every 8 bit image data from the entire capture.txt
I'm not sure if the contents of the capture.txt file which is feeded to the inject node could be treated as buffer. If you had a look at the attached file you may understand what I mean to say. And I also tried your loop with the captured data but it gives error if I try to pass it as a string to the inject node and doesn't give the desired result if i try to pass it as a buffer.
a 4 bit nibble holds 4 bits and has a max value of 15.
So the file has spaces (and also ends on a single number 6 so is incomplete) however, to convert that to a buffer, you need to remove the spaces & use Buffer.from(filedata,"hex") e.g...
var data = msg.payload.replace(/\s/g, ''); //remove all spaces
var src = Buffer.from(data, "hex"); //convert string to buffer
now you have 2 more problems...
You probably need to convert the YCbCr to RBG.
This is not too difficult given the real format of the 16 bit data however you have another issue...
If not possible due to language or processing constraints, ask for meta data to also be transmitted (e.g. pixel format, image size etc - everything you would need to construct an image)
The developer told me that the "F1" (Y component of the image is 4 bit) and "40" (CbCr component - another 4 bit) resulting a 8 bit image data. When we get rid of CbCr component, that is "40" - a 4 bit image data, all we are left with is only Y component i.e., F1 - 4 bit only.
I will ask the developer to ponder over your recommendations.
The developer says that the data arrived here is the pixel data (raw) from the camera module. So all the meta data needed for image generation is not available. But the image size is 174 X 144 as indicated by the developer.