For my research, I would like to compile a code to change the picture pixel value from RGB to HSV and then to RGB if the V value is above a certain value.
But, to do that, I have to use cv2.cvtColor(src,code)
.
When I used cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
, It worked nice!
But When I used cv2.cvtColor( list or str , cv2.COLOR_HSV2BGR)
, It made ERROR....
I think src has to be image. Unfortunately, I had to use type list or str or ndarray..
I tried hard to make them image, but it's really hard task I think..
If you run the code below, numpy array is showing only with V channel first.
After close the window, I can see this error.
Traceback (most recent call last):
File "/home/sjw/PycharmProjects/untitled/hiccc.py", line 18, in img[i][j] = cv2.cvtColor(y, cv2.COLOR_HSV2BGR) TypeError: src is not a numpy array, neither a scalar
But my question is not only knowing this error but also made a completed code. I need your help..Please.... :(
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('/home/sjw/Pictures/seulgi.jpg')
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
img_h, img_s, img_v = cv2.split(img2)
plt.imshow(img_v, interpolation='nearest')
plt.show()
for i in range(1, 1001):
for j in range(1, 1501):
if img_v[i][j] > 125:
y=''.join(str(v) for v in img_v[i:i][j:j])
print(type(y))
img[i][j] = cv2.cvtColor(y, cv2.COLOR_HSV2BGR)
cv2.imshow('sadd',img)
cv2.waitKey(0)
cv2.destroyAllWindows()