enable python3
This commit is contained in:
+34
-11
@@ -1,4 +1,3 @@
|
|||||||
# !/usr/bin/env python2
|
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
#
|
#
|
||||||
# =======================================================================
|
# =======================================================================
|
||||||
@@ -33,32 +32,46 @@
|
|||||||
# =======================================================================
|
# =======================================================================
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import argparse
|
import argparse
|
||||||
import ConfigParser as configparser
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import commands
|
import getpass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
except:
|
except:
|
||||||
ret, output = commands.getstatusoutput('whoami')
|
'''
|
||||||
|
output = getpass.getuser()
|
||||||
if output != 'root':
|
if output != 'root':
|
||||||
print('[ERROR] opencv-python not installed.')
|
print('[ERROR] opencv-python not installed.')
|
||||||
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('begin to install opencv-python...')
|
'''
|
||||||
ret = os.system('yum install -y opencv-python')
|
print('[info] begin to install opencv-python...')
|
||||||
if ret != 0:
|
if sys.version_info.major == 2:
|
||||||
ret = os.system('apt-get install -y python-opencv')
|
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')
|
||||||
|
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)
|
||||||
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
try:
|
try:
|
||||||
import numpy as np
|
import numpy as np
|
||||||
except:
|
except:
|
||||||
os.system('pip2 install numpy')
|
if sys.version_info.major == 2:
|
||||||
|
os.system('pip2 install numpy')
|
||||||
|
else:
|
||||||
|
os.system('python3.7.5 -m pip install numpy')
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
@@ -136,7 +149,17 @@ def convert_img(args, input_img):
|
|||||||
|
|
||||||
|
|
||||||
def resize_img(args, input_img):
|
def resize_img(args, input_img):
|
||||||
resized_img = cv.resize(input_img, (args.width, args.height))
|
old_size = input_img.shape[0:2]
|
||||||
|
target_size = [args.height, args.width]
|
||||||
|
ratio = min(float(target_size[i])/(old_size[i]) for i in range(len(old_size)))
|
||||||
|
new_size = tuple([int(i*ratio) for i in old_size])
|
||||||
|
img_new = cv.resize(input_img,(new_size[1], new_size[0]))
|
||||||
|
pad_w = target_size[1] - new_size[1]
|
||||||
|
pad_h = target_size[0] - new_size[0]
|
||||||
|
top,bottom = pad_h//2, pad_h-(pad_h//2)
|
||||||
|
left,right = pad_w//2, pad_w -(pad_w//2)
|
||||||
|
resized_img = cv.copyMakeBorder(img_new, top, bottom, left, right, cv.BORDER_CONSTANT, None,(0, 0, 0))
|
||||||
|
#resized_img = cv.resize(input_img, (args.width, args.height))
|
||||||
return resized_img
|
return resized_img
|
||||||
|
|
||||||
|
|
||||||
@@ -243,7 +266,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.")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user