on-internet
← Community

what is the error : "ValueError: assignment destination is read-only"?

Stack Overflow ·

When I am opening a jpg file using cv2.imread() and it fails sometimes which is likely due to BGR format I used. So I switched to PLT to use RGB. import matplotlib.pyplot as plt import numpy as np def rgb_to_gray(img): grayImage = np.zeros(img.shape) R = np.array(img[:, :, 0]) G = np.array(img[:, :, 1]) B = np.array(img[:, :, 2]) R = (R *.299) G = (G *.587) B = (B *.114) Avg = (R+G+B) grayImage = img for i in range(3): grayImage[:,:,i] = Avg return grayImage image_file = 'C:\A.jpg'; img = plt.imread(image_file,0) gray = rgb_to_gray(img).copy() How ever I am getting an error when I convert the

Comments

Sign in or sign up to comment and upvote.

No comments yet.