Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can i get the input images before converting them to lmdb #34

Open
kanika02 opened this issue Mar 14, 2022 · 2 comments
Open

Can i get the input images before converting them to lmdb #34

kanika02 opened this issue Mar 14, 2022 · 2 comments

Comments

@kanika02
Copy link

No description provided.

@kanika02
Copy link
Author

or can you provide the code for converting lmdb to images in one folder

@Everythingismetaphor
Copy link

or can you provide the code for converting lmdb to images in one folder

import cv2
import lmdb
import numpy as np
import os
root_path = 'D:\Python_Project\TextSR\TextZoom-master\dataset\lmdb\str\TextZoom/'
sub_path = 'test/medium/'
save_path='./Images/' + sub_path # 图片存储路径
if not os.path.exists(save_path):
    os.mkdir(save_path)
env = lmdb.open(root_path+sub_path)
imgdir_list1 = []
imgdir_list2 = []
label_list = []
with env.begin(write=False) as txn:
    for key, value in txn.cursor():
        type = key.decode('utf-8').split('-')[0]
        if key.decode('utf-8') == 'num-samples':
            print(key ,value)
            break
        if type!='label':
            if type.split('_')[1] == 'hr':   # hr图像
                image_name = key.decode('utf-8')
                image_buf = np.frombuffer(value, dtype=np.uint8)
                # # 将数据转换(解码)成图像格式
                # # cv2.IMREAD_GRAYSCALE为灰度图,cv2.IMREAD_COLOR为彩色图
                img = cv2.imdecode(image_buf, cv2.IMREAD_COLOR)
                cv2.imwrite(save_path + image_name + '.png', img)
                imgdir_list1.append(save_path + image_name + '.png')
            else:  # lr图像
                image_name = key.decode('utf-8')
                image_buf = np.frombuffer(value, dtype=np.uint8)
                # # 将数据转换(解码)成图像格式
                # # cv2.IMREAD_GRAYSCALE为灰度图,cv2.IMREAD_COLOR为彩色图
                img = cv2.imdecode(image_buf, cv2.IMREAD_COLOR)
                cv2.imwrite(save_path + image_name + '.png', img)
                imgdir_list2.append(save_path + image_name + '.png')
        else:  # 标签
            label_list.append(value.decode('utf-8'))
            print(key ,value)
env.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants