Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change size of image and fir it into numpy array opencv

# image variable is the image we are manipulating

output_img = np.ones((300, 300, 1)) * 128
output_img = (output_img).astype('uint8')

scale = 300 / (image.shape[0] * 1.0)
image_resize = cv2.resize(image, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_LANCZOS4)

img_w = image_resize.shape[1]

if img_w < 300:
    #pad the image with values and make it 1:1 aspect ratio
    offset = img_w % 2
    output_img[:, int(300 / 2 - math.floor(img_w / 2)):int(300 / 2 + math.floor(img_w / 2) + offset), :] = image_resize

else:
    #crop the center of the image to maintain 1:1 aspect ratio
    output_img = image_resize[:,int(img_w / 2 - 300 / 2):
                  int(img_w / 2 + 300 / 2), :]
Comment

PREVIOUS NEXT
Code Example
Python :: python filter function using lambda function as one of the parameters 
Python :: not want to assign all values of a collection of values in python 
Python :: Using rstrip() method to remove the newline character from a string 
Python :: List Creating List 
Python :: append to a ldictionary value list 
Python :: custom-field-list_display 
Python :: the coding train 
Python :: how to apply class method to pandas python 
Python :: convert integer to binary python 
Python :: python subtract days from date 
Python :: cors python functions framework local 
Python :: networkx draw edge description 
Python :: plot bar chart python with resulting numbers 
Python :: Python - Comment convertir la corde à la date 
Python :: add hours to date time in python 
Python :: membuat chat bot dengan python 
Python :: http://techforcurious.website/simulation-of-pendulum-vpython-tutorial-visual-python/ 
Python :: how to send more than one variables to python using xlwings 
Python :: Kinesis Client get_records example 
Python :: python3 subprocess getoutput 
Python :: random module randint 
Python :: how to create a login page in python 
Python :: python plot auc 95% confidence intervals stackoverflow 
Python :: if function has no argument python 
Python :: xmlrpc get all posts 
Python :: python getattr function 
Python :: fromhex python 2.7 
Python :: ValueError: Could not load "" Reason: "broken data stream when reading image file" 
Python :: blockchain.py 
Python :: python create dynamic 2d array 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =