lsun icon indicating copy to clipboard operation
lsun copied to clipboard

How can I conver .webp to .png?

Open gsygsy96 opened this issue 7 years ago • 5 comments

I try to utilize this dataset to train my network.But After I export those dataset,I found those're .webp file. So could you tell me how to convert to .png? PS: When I directly train my network with lmdb files in the dataset,an error occurred .Maybe lmdb files have somthing wrong I guess. error: F0326 01:27:43.210084 15934 data_transformer.cpp:734] Check failed: datum_channels > 0 (0 vs. 0)

gsygsy96 avatar Mar 25 '17 17:03 gsygsy96

Did you solve the problem? @shanYanGuan

zikai1 avatar Jun 04 '18 07:06 zikai1

Hi @mehameha998 and @zikai1 , In default, OpenCV can support the convertion from .webp to .jpg. I provide the simple script to convert the image into .jpg format.

# convert.py

from tqdm import tqdm
import argparse
import cv2
import os

parser = argparse.ArgumentParser()
parser.add_argument('--indir', help = "The path of the flat folder")
parser.add_argument('--outdir', help = "The path of the output folder")
args = parser.parse_args()

if not os.path.exists(args.outdir):
	os.mkdir(args.outdir)
for img_name in tqdm(os.listdir(args.indir)):
	img = cv2.imread(os.path.join(args.indir, img_name))
	cv2.imwrite(os.path.join(args.outdir, img_name[:-5] + '.jpg'), img) 

The procedure step is list below: First, you should extract the mdb file into flat format.

python2.7 data.py export <image db path> --out_dir <output directory> --flat

Next, run the following code to transfer the whole file into JPG format.

python3 convert.py --indir <output_directory> --outdir <final_output_directory>

SunnerLi avatar Oct 31 '18 06:10 SunnerLi

Hi @mehameha998 and @zikai1 , In default, OpenCV can support the convertion from .webp to .jpg. I provide the simple script to convert the image into .jpg format.

# convert.py

from tqdm import tqdm
import argparse
import cv2
import os

parser = argparse.ArgumentParser()
parser.add_argument('--indir', help = "The path of the flat folder")
parser.add_argument('--outdir', help = "The path of the output folder")
args = parser.parse_args()

if not os.path.exists(args.outdir):
	os.mkdir(args.outdir)
for img_name in tqdm(os.listdir(args.indir)):
	img = cv2.imread(os.path.join(args.indir, img_name))
	cv2.imwrite(os.path.join(args.outdir, img_name[:-5] + '.jpg'), img) 

The procedure step is list below: First, you should extract the mdb file into flat format.

python2.7 data.py export <image db path> --out_dir <output directory> --flat

Next, run the following code to transfer the whole file into JPG format.

python3 convert.py --indir <output_directory> --outdir <final_output_directory>

It doesn't work. Which version of opencv are you using?

$ python3 convert.py --indir bedroom_train_lmdb --outdir bedroom_train_lmdb
  0%|                                                                                                                                                                                       | 0/18 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "convert.py", line 16, in <module>
    cv2.imwrite(os.path.join(args.outdir, img_name[:-5] + '.jpg'), img) 
cv2.error: OpenCV opencv/modules/imgcodecs/src/loadsave.cpp:740: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'

i-chaochen avatar Dec 18 '19 10:12 i-chaochen

Hi @mehameha998 and @zikai1 , In default, OpenCV can support the convertion from .webp to .jpg. I provide the simple script to convert the image into .jpg format.

# convert.py

from tqdm import tqdm
import argparse
import cv2
import os

parser = argparse.ArgumentParser()
parser.add_argument('--indir', help = "The path of the flat folder")
parser.add_argument('--outdir', help = "The path of the output folder")
args = parser.parse_args()

if not os.path.exists(args.outdir):
	os.mkdir(args.outdir)
for img_name in tqdm(os.listdir(args.indir)):
	img = cv2.imread(os.path.join(args.indir, img_name))
	cv2.imwrite(os.path.join(args.outdir, img_name[:-5] + '.jpg'), img) 

The procedure step is list below: First, you should extract the mdb file into flat format.

python2.7 data.py export <image db path> --out_dir <output directory> --flat

Next, run the following code to transfer the whole file into JPG format.

python3 convert.py --indir <output_directory> --outdir <final_output_directory>

It doesn't work. Which version of opencv are you using?

$ python3 convert.py --indir bedroom_train_lmdb --outdir bedroom_train_lmdb
  0%|                                                                                                                                                                                       | 0/18 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "convert.py", line 16, in <module>
    cv2.imwrite(os.path.join(args.outdir, img_name[:-5] + '.jpg'), img) 
cv2.error: OpenCV opencv/modules/imgcodecs/src/loadsave.cpp:740: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'

I got the same error. Did you solve the problem?

littlejuyan avatar Jul 17 '21 13:07 littlejuyan

I try to utilize this dataset to train my network.But After I export those dataset,I found those're .webp file. So could you tell me how to convert to .png? PS: When I directly train my network with lmdb files in the dataset,an error occurred .Maybe lmdb files have somthing wrong I guess. error: F0326 01:27:43.210084 15934 data_transformer.cpp:734] Check failed: datum_channels > 0 (0 vs. 0)

If you want jpg format, you can modify the code directly in the export_images image_out_path = join(image_out_dir, key.decode('ascii') + '.jpg') # image_out_path = join(image_out_dir, key.decode('ascii') + '.webp')

gaofang-123 avatar Apr 28 '22 01:04 gaofang-123