Giter Site home page Giter Site logo

Comments (2)

kanika02 avatar kanika02 commented on July 24, 2024

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

from fudanocr.

Everythingismetaphor avatar Everythingismetaphor commented on July 24, 2024

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

from fudanocr.

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.