2-5NegaPosi_gpu.py

000: import cv2
001:
002: def __main():
003: gpuImg = cv2.cuda_GpuMat()
004: img = cv2.imread(‘../IMG_1029.JPG’)
005: gpuImg.upload(img)
006:
007: # ここで処理を実行
008: gpuImg = getGpuResize(gpuImg)
009: gpuImg = cv2.cuda.bitwise_not(gpuImg)
010:
011: img = gpuImg.download()
012:
013: cv2.imshow(‘Final result’, img)
014: cv2.waitKey(0)
015: cv2.destroyAllWindows()
016:
017: return 0
018:
019: def getGpuResize(gpuSrc):
020: basePixSize = 1280 # 縦横で大きい辺の変更したいサイズ
021: width, height = gpuSrc.size()
022:
023: largeSize = max(height, width) # 大きい方の辺のサイズ
024: resizeRate = basePixSize / largeSize # 変更比率を計算
025: dst = cv2.cuda.resize(gpuSrc, (int(width * resizeRate), int(height * resizeRate)))
026:
027: return dst
028:
029: if __name__ == ‘__main__’:
030: print(cv2.__version__)
031:
032: __main()