-
Can someone help me with getting this working, not well versed in the esp-idf c world. I'm sure its a simple fix. I allocated the destination bytearray in micropython and can call the function successfully but the buffer is getting de-allocated. #include "img_converters.h"
#include "esp_jpg_decode.h"
static mp_obj_t rgb888(mp_obj_t src_obj, mp_obj_t len_obj, void *dest_obj) {
uint8_t *src = MP_OBJ_TO_PTR(src_obj);
int src_len = mp_obj_get_int(len_obj);
//uint8_t * _rgb888 = (uint8_t *) m_malloc(3*480*320);
if (fmt2rgb888(src, src_len, PIXFORMAT_JPEG, dest_obj)) {
//return MP_OBJ_FROM_PTR(_rgb888);
return mp_obj_new_bool(1);
} else {
return mp_obj_new_bool(0);
}
} f = open('land.jpg','rb')
jpg = f.read()
f.close()
from imageconv import rgb888
rgb = bytearray(3*480*320)
rgb888(jpg, len(jpg), rgb) # True
rgb
NameError: name 'rgb' isn't defined |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 22 replies
-
That is not the correct way to access a bytearray. Neither for src_obj nor for dest_obj :D See https://github.com/orgs/micropython/discussions/16834 for some ways of doing it. The array carries its own length with it, so you just need mp_obj_t src_obj, mp_obj_t dest_obj As you are onto here, it is much better to let the function take parameter also with the destinationn array (instead of doing malloc inside). That way allocations can be reused by the caller. And creating such objects is more practical in Python anyway. I also think there is code for this transformation in https://github.com/cnadler86/micropython-camera-API |
Beta Was this translation helpful? Give feedback.
-
Use this Decoder: https://github.com/cnadler86/mp_jpeg Much faster and already in Micropython. I suggest to download the firmware from the latest workflow |
Beta Was this translation helpful? Give feedback.
-
Most cameras have the ability to flip vertical and/or horizontal (alone
with rotation), typically configurable via som registers. Because cameras
are mounted in all kinds of ways.
That would be much more efficient than flipping back in the application.
|
Beta Was this translation helpful? Give feedback.
Use this Decoder: https://github.com/cnadler86/mp_jpeg
Much faster and already in Micropython. I suggest to download the firmware from the latest workflow