Ask Your Question
1

cv2 imdecode webp format fails

asked 2019-03-25 18:08:35 -0500

comip gravatar image

updated 2019-03-26 01:45:26 -0500

LBerger gravatar image

(I'm using OpenCV 4.0.1)

_bytes = open('xxxx.webp', 'rb').read()
_buf   = np.frombuffer(_bytes, np.uint8)
_img   = cv2.imdecode(_buf, cv2.IMREAD_UNCHANGED)
assert _img is not None   # returns None

(I'm using OpenCV 4.0.1)

edit retag flag offensive close merge delete

Comments

check print(cv2.getBuildInformation()) if webp is available

LBerger gravatar imageLBerger ( 2019-03-26 03:11:28 -0500 )edit

I checked. Webp is there. B.t.w. What does "(ver encoder: 0x020e)" means? No webp decoder?

  Media I/O: 
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 1.5.3-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.35)
    TIFF:                        build (ver 42 - 4.0.9)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

And when I use cv2.imencode for webp, everything is fine.

comip gravatar imagecomip ( 2019-03-26 04:23:56 -0500 )edit

And when I directly read from file, it is also fine:

im = cv2.imread('xxx.webp')
comip gravatar imagecomip ( 2019-03-26 04:25:23 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-03-26 05:30:00 -0500

LBerger gravatar image

updated 2019-03-26 05:31:15 -0500

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

edit flag offensive delete link more

Comments

1

Thanks LBerger. Are you going to open an issue on github?

comip gravatar imagecomip ( 2019-03-26 07:16:24 -0500 )edit

you can post your issue

LBerger gravatar imageLBerger ( 2019-03-26 08:33:39 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-03-25 18:03:03 -0500

Seen: 41 times

Last updated: Mar 26