# USAGE
# python adjust_gamma.py
# import the necessary packages
from __future__ import print_function
import numpy as np
import argparse
import cv2
def adjust_gamma(image, gamma=1.0):
# build a lookup table mapping the pixel values [0, 255] to
# their adjusted gamma values
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
# apply gamma correction using the lookup table
return cv2.LUT(image, table)
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="C:\Users\mesco\Desktop\h.jpg")
args = vars(ap.parse_args())
# load the original image
original = cv2.imread(args["image"])
# loop over various values of gamma
for gamma in np.arange(0.0, 3.5, 0.5):
# ignore when gamma is 1 (there will be no change to the image)
if gamma == 1:
continue
# apply gamma correction and show the images
gamma = gamma if gamma > 0 else 0.1
adjusted = adjust_gamma(original, gamma=gamma)
cv2.putText(adjusted, "g={}".format(gamma), (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
cv2.imshow("Images", np.hstack([original, adjusted]))
cv2.waitKey(0)
У меня была ошибка, которая говорит ->
File "C:\Users\mesco\Desktop\adjust_gamma.py", line 30, in <module>
adjusted = adjust_gamma(original, gamma=gamma)
File "C:\Users\mesco\Desktop\adjust_gamma.py", line 12, in adjust_gamma
return cv2.LUT(image, table)
cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\core\src\matrix.cpp:406: error: (-215:Assertion failed) m.dims >= 2 in function 'cv::Mat::Mat'
, пожалуйста, помогите, я работал над гамма-коррекцией для моей магистерской диссертации. Может ли кто-нибудь помочь в этом вопросе, я установил OpenCV 4.1.2 на свой ноутбук, и я не могу найти какие-либо решения для решения этой ошибки. Спасибо за вашу помощь, кстати!