diff --git a/img2bin/img2bin.py b/img2bin/img2bin.py index ff934af..2f149e4 100644 --- a/img2bin/img2bin.py +++ b/img2bin/img2bin.py @@ -32,12 +32,10 @@ # ======================================================================= from __future__ import print_function import argparse - -import json import os import sys -import getpass - +import json +# import getpass try: import cv2 as cv except: @@ -48,23 +46,36 @@ except: print("[ERROR] Please use the root user to execute this script again") exit(0) ''' - print('[info] begin to install opencv-python...') if sys.version_info.major == 2: - import ConfigParser as configparser - ret = os.system('sudo yum install -y opencv-python') - if ret != 0: - ret = os.system('sudo apt-get install -y python-opencv') + confirm = raw_input("[info] Begin to install opencv-python, input[Y/N]:") + else: + confirm = input("[info] Begin to install opencv-python, input[Y/N]:") + + if confirm == 'Y' or confirm == 'y': + print('[info] Starting to install opencv-python...') + if sys.version_info.major == 2: + import commands + import ConfigParser as configparser + ret, output = commands.getstatusoutput("sudo yum install -y opencv-python") + # ret = os.popen('sudo yum install -y opencv-python') + if ret != 0: + # ret = os.popen('sudo apt-get install -y python-opencv') + ret, output = commands.getstatusoutput("sudo apt-get install -y python-opencv") + if ret != 0: + print('[ERROR] install opencv-python failed,please check env.') + exit(0) + else: + import configparser + ret = os.system('python3.7.5 -m pip install opencv-python -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com') if ret != 0: print('[ERROR] install opencv-python failed,please check env.') exit(0) - else: - import configparser - ret = os.system('python3.7.5 -m pip install opencv-python -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com') - if ret != 0: - print('[ERROR] install opencv-python failed,please check env.') - exit(0) - import cv2 as cv + import cv2 as cv + else: + print("[info] The installation has been cancled.") + exit(0) + try: import numpy as np except: @@ -77,9 +88,9 @@ except: def get_args(): parser = argparse.ArgumentParser( conflict_handler='resolve', - description='''eg1: python2 imgtobin.py + description='''eg1: python2 img2bin.py -i ./images -w 416 -h 416 -f BGR -a NHWC -t uint8 -m [104,117,123] -c [1,1,1] -o ./out - eg2: python2 imgtobin.py -i ./test.txt -t uint8 -o ./out''') + eg2: python2 img2bin.py -i ./test.txt -t uint8 -o ./out''') parser.add_argument('-i', '--input', required=True, type=str, \ help='folder of input image or file of other input.') parser.add_argument('-w', '--width', type=int, \ @@ -266,7 +277,7 @@ def main(): process(args, file_path) else: process(args, args.input) - print("[info] bin file generated successfully.") + print("[info] bin file generated successfully.") if __name__ == '__main__': main()