프로그래밍/C++

[NH] centos 7 python3 easyOCR 사용하기 위한 기본 모듈 설치

소행성왕자 2021. 12. 10. 14:08
기본 패키지 설치 (root 계정 실행)
$ yum -y update
$ yum -y groupinstall 'Development Tools'
$ yum -y install \
        wget \
        git \
        gcc \
        openssl-devel \
        bzip2-devel \
        python3.x86_64 \
        libffi-devel \
        g++ \
        opencv \
        opencv-devel \
        opencv-python\
        make

 

pypy 일반계정 추가
$ adduser pypy
일반 계정으로 전환
$ su pypy

파이썬 모듈 설치

$ python3 -m pip install --upgrade pip && pip install setuptools
$ python3 -m pip install torch==1.9.0 torchvision==0.10.0 pyinstaller
$ python3 -m pip install fastapi==0.60.1 uvicorn==0.11.8 pillow requests numpy scikit-image scipy python-bidi pyyaml opencv-python
압축파일 easyOCR-binary-centos-main.tar.gz
/home/pypy 경로에 복사 후 압축해제
실제 경로 /home/pypy/easyOCR-binary-centos-main
[pypy@c74363afaa94 easyOCR-binary-centos-main]$ ll
total 16
-rw-rw-r-- 1 1001 1001 635 Aug  3 02:06 Makefile
-rw-rw-r-- 1 1001 1001 757 Oct  6 05:46 README.md
drwxrwxr-x 2 1001 1001  44 Aug  3 02:06 character
drwxrwxr-x 2 1001 1001  24 Dec  7 07:15 docker
drwxrwxr-x 5 1001 1001 219 Oct 25 06:18 easyOCR
-rw-rw-r-- 1 1001 1001 607 Oct  6 08:00 server.py
drwxrwxr-x 5 1001 1001  89 Oct 25 07:59 src
drwxrwxr-x 2 1001 1001 139 Dec  7 08:20 tests
drwxrwxr-x 2 1001 1001  49 Oct  6 08:25 weight
-rw-rw-r-- 1 1001 1001  54 Aug  3 02:06 weight_download.py
OCR 분석하기 위한 파이썬 서버 실행
$ python3 ./server.py &



압축파일 cpptest.tar.gz

/home/pypy/ 경로에 복사 후 압축해제

실제 경로 /home/pypy/cpptest
$ ls -al /home/pypy/cpptest
-rw-rw-r-- 1 1001 1001    809 Dec  7 04:22 client.py
-rwxrwxr-x 1 1001 1001  28720 Dec  8 06:27 cpp
-rw-rw-r-- 1 1001 1001   1350 Dec  8 06:27 cpp.cpp
-rw-rw-r-- 1 1001 1001 134936 Dec  7 04:19 example.jpeg

 

소유권 변경
$ chown pypy.pypy -R ./



pypy 일반계정으로 컴파일
$ g++ -o cpp cpp.cpp
실행
$ ./cpp

결과

>>output
[([[46, 42], [136, 42], [136, 72], [46, 72]], '1종보통', 0.9726952910423279), ([[326, 60], [652, 60], [652, 92], [326, 92]], '자동차운전면허증 ODrivers License)', 0.26227813959121704), ([[273, 83], [610, 83], [610, 135], [273, 135]], '19-11-600681-41', 0.8405309915542603), ([[273, 137], [367, 137], [367, 175], [273, 175]], '김선경', 0.9976277351379395), ([[273, 167], [501, 167], [501, 203], [273, 203]], '910420-2042119', 0.5177139639854431), ([[274, 202], [626, 202], [626, 232], [274, 232]], '경기도 성남시ㆍ분당구 성남대로', 0.45874926447868347), ([[269, 223], [365, 223], [365, 283], [269, 283]], '3봇롱', 0.7032102346420288), ([[270, 226], [338, 226], [338, 256], [270, 256]], '343번', 0.9975982904434204), ([[366, 228], [388, 228], [388, 252], [366, 252]], '9', 0.9974496364593506), ([[270, 280], [374, 280], [374, 312], [270, 312]], '적성검사', 0.9967686533927917), ([[394, 282], [530, 282], [530, 308], [394, 308]], '2028.01.01', 0.8440883755683899), ([[274, 306], [304, 306], [304, 336], [274, 336]], '기', 0.7197038531303406), ([[348, 308], [376, 308], [376, 336], [348, 336]], '간', 0.6451607942581177), ([[432, 308], [576, 308], [576, 336], [432, 336]], '2028.12.31.', 0.7578035593032837), ([[269, 385], [665, 385], [665, 429], [269, 429]], '2018.04.20.경기남부지방경찰청장', 0.6130582690238953)]
[([[46, 42], [136, 42], [136, 72], [46, 72]], '1종보통', 0.9726952910423279
, ([[326, 60], [652, 60], [652, 92], [326, 92]], '자동차운전면허증 ODrivers License
', 0.26227813959121704
, ([[273, 83], [610, 83], [610, 135], [273, 135]], '19-11-600681-41', 0.8405309915542603
, ([[273, 137], [367, 137], [367, 175], [273, 175]], '김선경', 0.9976277351379395
, ([[273, 167], [501, 167], [501, 203], [273, 203]], '910420-2042119', 0.5177139639854431
, ([[274, 202], [626, 202], [626, 232], [274, 232]], '경기도 성남시ㆍ분당구 성남대로', 0.45874926447868347
, ([[269, 223], [365, 223], [365, 283], [269, 283]], '3봇롱', 0.7032102346420288
, ([[270, 226], [338, 226], [338, 256], [270, 256]], '343번', 0.9975982904434204
, ([[366, 228], [388, 228], [388, 252], [366, 252]], '9', 0.9974496364593506
, ([[270, 280], [374, 280], [374, 312], [270, 312]], '적성검사', 0.9967686533927917
, ([[394, 282], [530, 282], [530, 308], [394, 308]], '2028.01.01', 0.8440883755683899
, ([[274, 306], [304, 306], [304, 336], [274, 336]], '기', 0.7197038531303406
, ([[348, 308], [376, 308], [376, 336], [348, 336]], '간', 0.6451607942581177
, ([[432, 308], [576, 308], [576, 336], [432, 336]], '2028.12.31.', 0.7578035593032837
, ([[269, 385], [665, 385], [665, 429], [269, 429]], '2018.04.20.경기남부지방경찰청장', 0.6130582690238953
]

 

원인:

python2 가 설치되어 있고 python3 repo 없다

1. 리포추가

2.일반계정 path 를 새로설치한 것을 우선

 

yum install -y epel-release.noarch

yum install -y https://repo.ius.io/ius-release-el7.rpm 

yum install -y python36u python36u-libs python36u-pip

python3 get-pip --user

일반계정 .bash_profile 수정

PATH = $HOME/.local/bin:$PATH:$HOME/bin