1 | initial version |
It works in C++ :
Mat img = imread("g:/lib/opencv/samples/data/lena.jpg");
imwrite("test.webp", img);
fstream fs;
fs.open("test.webp", ios::binary + ios::in);
fs.seekg(0, fs.end);
int length = fs.tellg();
fs.seekg(0, fs.beg);
std::vector<uchar> buffer(length);
fs.read((char*)&buffer[0], length);
fs.close();
vector<uchar> tmp;
Mat img2= imdecode(buffer, IMREAD_UNCHANGED);
imshow("e",img2 );
waitKey();
In python
import numpy as np
import cv2 as cv
_bytes = open('test.webp', 'rb').read()
buf = np.frombuffer(_bytes, np.uint8)
img = cv.imdecode(buf, cv.IMREAD_UNCHANGED)
error is imdecode_(''): can't read data: OpenCV(4.1.0-pre) G:\Lib\opencv\modules\imgcodecs\src\grfmt_webp.cpp:164: error: (-215:Assertion failed) data.rows == 1 in function 'cv::WebPDecoder::readData'
I think python binding is wrong... post an issue
2 | No.2 Revision |
It works in C++ :
Mat img = imread("g:/lib/opencv/samples/data/lena.jpg");
imwrite("test.webp", img);
fstream fs;
fs.open("test.webp", ios::binary + ios::in);
fs.seekg(0, fs.end);
int length = fs.tellg();
fs.seekg(0, fs.beg);
std::vector<uchar> buffer(length);
fs.read((char*)&buffer[0], length);
fs.close();
vector<uchar> tmp;
Mat img2= imdecode(buffer, IMREAD_UNCHANGED);
imshow("e",img2 );
waitKey();
In python
import numpy as np
import cv2 as cv
_bytes = open('test.webp', 'rb').read()
buf = np.frombuffer(_bytes, np.uint8)
img = cv.imdecode(buf, cv.IMREAD_UNCHANGED)
error is imdecode_(''): can't read data: OpenCV(4.1.0-pre) G:\Lib\opencv\modules\imgcodecs\src\grfmt_webp.cpp:164: error: (-215:Assertion failed) data.rows == 1 in function 'cv::WebPDecoder::readData'
I think python binding is wrong... np.uint8 is convert in char and it should be uchar post an issue