# python study
import numpy as np
import cv2
#img = cv2.imread('bongdu.jpg')
img_nam = "C:\Users\jhjoo\Desktop\bongdu.jpg"
img_name = img_nam.replace("\", "/")
img = cv2.imread(img_name)
[height, width, channel] = img.shape
#img_gray = np.zeros((height,width), np.uint8)
img_gray = img.copy()
#print(height, width, channel)
for y in range(np.round(height // 4), np.round(height // 4 * 3)):
for x in range(np.round(width // 4), np.round(width // 4 * 3)):
r = img.item(y, x, 2)
g = img.item(y, x, 1)
b = img.item(y, x, 0)
gray = (int(r) + int(g) + int(b)) / 3
if gray > 255:
gray = 255
#img_gray.itemset(y, x, gray)
img_gray[y][x] = gray
cv2.imshow('bongdu',img)
cv2.imshow('bongdu_gray',img_gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
I'm practicing by writing the code like above
#img = cv2.imread('bongdu.jpg')
img_nam = "C:\Users\jhjoo\Desktop\bongdu.jpg"
img_name = img_nam.replace("\", "/")
img = cv2.imread(img_name)
In this part, we have confirmed that absolute paths cannot be executed if they are set to \, and only if they are set to /. But I'm lazy to change the path to / one by one because I usually copy it from the explorer I want to insert a code that automatically changes \ to / I don't think the replace function is applied.
I wonder what I should do.
On this site, \ appears in the shape of \, but in Python code, it looks like money.
img_nam = r"C:\Users\jhjoo\Desktop\bongdu.jpg"
Use it like this.
561 PHP ssh2_scp_send fails to send files as intended
555 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
783 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
554 Uncaught (inpromise) Error on Electron: An object could not be cloned
555 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.