Resize image in OpenCV Python

import cv2
import numpy as np

image = cv2.imread("cow.jpg")
print(image.shape)  # (559, 838, 3)

old_width = image.shape[1]  # 838
old_height = image.shape[0]  # 559

# resize by custom size
new_width = 600
new_height = 400
resized = cv2.resize(image, (new_width, new_height))
cv2.imshow("image", resized)

# resize by ratio
width_ratio = 0.5
height_ration = 0.5
resized2 = cv2.resize(image, (0, 0), image, width_ratio, height_ration)
cv2.imshow("image2", resized2)

cv2.waitKey(0)
cv2.destroyAllWindows()

References
https://github.com/mhdr/OpenCVSamples/tree/master/008

Preventing Windows OS from sleeping while your python code runs

class WindowsInhibitor:
    '''Prevent OS sleep/hibernate in windows; code from:
    https://github.com/h3llrais3r/Deluge-PreventSuspendPlus/blob/master/preventsuspendplus/core.py
    API documentation:
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa373208(v=vs.85).aspx'''
    ES_CONTINUOUS = 0x80000000
    ES_SYSTEM_REQUIRED = 0x00000001

    def __init__(self):
        pass

    def inhibit(self):
        import ctypes
        print("Preventing Windows from going to sleep")
        ctypes.windll.kernel32.SetThreadExecutionState(
            WindowsInhibitor.ES_CONTINUOUS | \
            WindowsInhibitor.ES_SYSTEM_REQUIRED)

    def uninhibit(self):
        import ctypes
        print("Allowing Windows to go to sleep")
        ctypes.windll.kernel32.SetThreadExecutionState(
            WindowsInhibitor.ES_CONTINUOUS)
import os

osSleep = None
# in Windows, prevent the OS from sleeping while we run
if os.name == 'nt':
    osSleep = WindowsInhibitor()
    osSleep.inhibit()

# do slow stuff

if osSleep:
    osSleep.uninhibit()

References
https://trialstravails.blogspot.com/2017/03/preventing-windows-os-from-sleeping.html