-
I tried to use stbi_load_from_memory, but got NULL int height = image.cols;
int width = image.rows;
int channel = image.channels();
if(!image.isContinuous()){
printf("clone!\n");
image=image.clone();
}
unsigned char * imageData = (unsigned char *)image.data;
size_t img_length = image.total() * image.elemSize();
unsigned char* image_data = stbi_load_from_memory(imageData, img_length, &width, &height, &channel, 3); I also tried code which was found in Mat buf = _buf.getMat();
if (!buf.isContinuous())
{
buf = buf.clone();
}
size_t buf_size = buf.cols * buf.rows * buf.elemSize();
int w;
int h;
int c;
unsigned char* pixeldata = stbi_load_from_memory((const unsigned char*)buf.data, buf_size, &w, &h, &c, desired_channels); I found stbi__load_main run to : return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt"); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
stb_image is used to load image files. PNG, JPG, BMP etc. A cv::Mat is already an array of pixels in memory, which is the result of what stb_image would do, not the input to it. There's no loading step involved. You can just access the bytes in the cv::Mat directly (using Either way, you seem to have a OpenCV question, not a stb_image question, so you'll have better odds of getting an answer there. |
Beta Was this translation helpful? Give feedback.
stb_image is used to load image files. PNG, JPG, BMP etc.
A cv::Mat is already an array of pixels in memory, which is the result of what stb_image would do, not the input to it. There's no loading step involved. You can just access the bytes in the cv::Mat directly (using
ptr
or other methods).Either way, you seem to have a OpenCV question, not a stb_image question, so you'll have better odds of getting an answer there.