grayscale framebuffer into uint8_t buffer
Closed this issue · 3 comments
MacBlackCat commented
Hey sorry for this novice question but I think im just missing something obvious... Would be very happy with the some guidance 🥇
code getting framebuffer
camera_fb_t * fb = NULL;
esp_err_t res = ESP_OK;
fb = esp_camera_fb_get(); // framebuffer in grayscale
and feed it somehow to quirc?
int w, h;
int i, count;
uint8_t *buf = quirc_begin(qr, &w, &h);
//
//Feed 'fb' into 'buf' somehow?
//
quirc_end(qr);
I've looked through the code, source files etc, but as i'm a novice ive no clue how to merge or copy the two buffers.
from esp32 code:
//replace this with your own function
display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);
dlbeer commented
On Thu, Jan 23, 2020 at 07:19:06AM -0800, MacBlackCat wrote:
Hey sorry for this novice question but I think im just missing something obvious... Would be very happy with the some guidance :1st_place_medal:
code getting framebuffer
```
camera_fb_t * fb = NULL;
esp_err_t res = ESP_OK;
fb = esp_camera_fb_get(); // framebuffer in grayscale
```
and feed it somehow to quirc?
```
int w, h;
int i, count;
uint8_t *buf = quirc_begin(qr, &w, &h);
//
//Feed 'fb' into 'buf' somehow?
//
quirc_end(qr);
```
I've looked through the code, source files etc, but as i'm a novice ive no clue how to merge or copy the two buffers.
from esp32 code:
```
//replace this with your own function
display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);
```
A frame buffer is just an array of pixels, usually stored row by row.
Each pixel is usually an 8, 16 or 32-bit value. Quirc uses 8-bit pixel
values, stored row by row, where 0 is black and 255 is white.
It looks like you have for the source:
fb->buf: a pointer to the array of pixels to copy from
fb->width, fb->height: the width and height of the source image
fb->pixformat: some information about what kind of pixels are stored
in buf
fb->len: total length of the array (not sure why you need that -- it
should just be width * height in this case)
In general, the pixel at (x, y) will be stored in element (y*w+x) of the
array. If you know that both arrays are storing their pixels in the same
order, you don't need to worry about that -- you just copy/convert the
elements one by one in sequence (w*h elements total).
You will generally have a loop like:
uint8_t *buf = quirc_begin(qw, &w, &h);
int total_pixels = w * h;
for (int i = 0; i < total_pixels; i++) {
// grab a pixel from your source image at element i
// convert it somehow, then store it
buf[i] = converted pixel value
}
quirc_end(qr);
If your source buffer is already 8-bit grayscale, then this is easy,
because you don't need to convert anything -- you just copy the existing
value.
The next step would be to find out what kind of pixels you have in the
source buffer.
Cheers,
Daniel
…--
Daniel Beer <dlbeer@gmail.com> http://dlbeer.co.nz/
PGP: BA6E 0B26 1F89 246C E3F3 C910 1E58 C43A 160A 553B
MacBlackCat commented
Luckily for me this is my camera config :D
config.pixel_format = PIXFORMAT_GRAYSCALE;
config.frame_size = FRAMESIZE_QVGA;
Going to try out your advice, and already thanks for actually explaining the whole concept.
MacBlackCat commented
@dlbeer Thanks for the reply, it works! Atleast my Serial output tells me it found 1 code, but that's enough for me. Tells me it gets through from the camera buffer into quirc!
int w, h;
int i, count;
uint8_t *buff = quirc_begin(qr, &w, &h);
//
int total_pixels = w * h;
for (int i = 0; i < total_pixels; i++) {
// grab a pixel from your source image at element i
// convert it somehow, then store it
buff[i] = fb->buf[i]; //?
}
//
quirc_end(qr);
count = quirc_count(qr);
Serial.println("count found codes:");
Serial.println(count);