Hi, I have function like this:
int GetCLAHEImage(char * image, int image_size, double clip_limit, int grid_size, int mode, char** image_out_data, int *image_out_length) {
std::vector<char> image_data(image, image+image_size);
auto matInfo = cv::Mat(image_data);
cv::Mat img = cv::imdecode(cv::Mat(image_data), 1);
applyClahe(img, clip_limit, grid_size, mode);
std::vector<uchar> buffer;
cv::imencode(".png", img, buffer);
*image_out_data = new char[buffer.size()];
*image_out_length = buffer.size();
memcpy(*image_out_data, &buffer[0], buffer.size());
return DE_NO_ERROR;
}
When I run it with a encoded png everything is fine, but running it with a encoded webp (image variable) I get the following error at the line of imdecode:
imdecode_(ââ): canât read data: OpenCV(4.5.2) /opencv-4.5.2/modules/imgcodecs/src/grfmt_webp.cpp:164: error: (-215:Assertion failed) data.type() == CV_8UC1 in function âreadDataâ
terminate called after throwing an instance of âcv::Exceptionâ
what(): OpenCV(4.5.2) /opencv-4.5.2/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function âcvtColorâ
SIGABRT: abort
PC=0x7f2498b65ef5 m=4 sigcode=18446744073709551610
I use opencv 4.5.2, c++ and manjaro linux (error also occurs on debian and ubuntu)
The function is part of a library and I call it using cgo
fmt.Println("image info: ", http.DetectContentType(img.ImageBytes))
// --> returns image/webp
imgBytesOut, err := mylib.GetCLAHEImage(img.ImageBytes, m.ClipLimit, m.TileSize, mylib.CLAHE_LAB)
with a go_wrapper:
func GetCLAHEImage(image []byte, clip_limit float64, grid_size int, mode int) ([]byte, error) {
var ret C.int
var retlen C.int
bytes := C.CString("")
ret = C.GetCLAHEImage((*C.char)(unsafe.Pointer(&image[0])), C.int(len(image)), C.double(clip_limit), C.int(grid_size), C.int(mode), &bytes, &retlen)
result := C.GoBytes(unsafe.Pointer(bytes), retlen)
C.free(unsafe.Pointer(bytes))
return result, nil
}
What could be wrong here? Is there a bug in opencv?