Giter Club home page Giter Club logo

Comments (5)

SunnerLi avatar SunnerLi commented on July 16, 2024 8

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>

from lsun.

zikai1 avatar zikai1 commented on July 16, 2024

Did you solve the problem?
@shanYanGuan

from lsun.

i-chaochen avatar i-chaochen commented on July 16, 2024

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'

from lsun.

littlejuyan avatar littlejuyan commented on July 16, 2024

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?

from lsun.

gaofang-123 avatar gaofang-123 commented on July 16, 2024

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')

from lsun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.