add confirm before install opencv

This commit is contained in:
HuaweiAscend
2020-07-10 03:53:57 -07:00
parent 66c1b3c528
commit 62d091bbb3
+30 -19
View File
@@ -32,12 +32,10 @@
# ======================================================================= # =======================================================================
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import json
import os import os
import sys import sys
import getpass import json
# import getpass
try: try:
import cv2 as cv import cv2 as cv
except: except:
@@ -48,23 +46,36 @@ except:
print("[ERROR] Please use the root user to execute this script again") print("[ERROR] Please use the root user to execute this script again")
exit(0) exit(0)
''' '''
print('[info] begin to install opencv-python...')
if sys.version_info.major == 2: if sys.version_info.major == 2:
import ConfigParser as configparser confirm = raw_input("[info] Begin to install opencv-python, input[Y/N]:")
ret = os.system('sudo yum install -y opencv-python') else:
if ret != 0: confirm = input("[info] Begin to install opencv-python, input[Y/N]:")
ret = os.system('sudo apt-get install -y python-opencv')
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: if ret != 0:
print('[ERROR] install opencv-python failed,please check env.') print('[ERROR] install opencv-python failed,please check env.')
exit(0) 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: try:
import numpy as np import numpy as np
except: except:
@@ -77,9 +88,9 @@ except:
def get_args(): def get_args():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
conflict_handler='resolve', 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 -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, \ parser.add_argument('-i', '--input', required=True, type=str, \
help='folder of input image or file of other input.') help='folder of input image or file of other input.')
parser.add_argument('-w', '--width', type=int, \ parser.add_argument('-w', '--width', type=int, \
@@ -266,7 +277,7 @@ def main():
process(args, file_path) process(args, file_path)
else: else:
process(args, args.input) process(args, args.input)
print("[info] bin file generated successfully.") print("[info] bin file generated successfully.")
if __name__ == '__main__': if __name__ == '__main__':
main() main()