Jika kamu belum mengetahui perbedaan mendasar format color di openCV yaitu BGR sedangkan dalam matplotlib adalah RGB sehingga ada perbedaan pada saat
menampilkan gambar dalam format truecolor seperti berikut
#format BGR yang berasal dari openCV
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('D:/citra.bmp')
plt.imshow(img)
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
while True:
k = cv2.waitKey(0) & 0xFF # 0xFF? To get the lowest byte.
if k == 27: break # Code for the ESC key
cv2.destroyAllWindows()
Kamu bandingkan dengan code berikut
#kasus mengubah format BGR opencv dengan RGB matplotlib
import cv2
import numpy as np
from matplotlib import pyplot as plt
bgr_img = cv2.imread('D:/citra.bmp')
b,g,r = cv2.split(bgr_img) # get b,g,r
rgb_img = cv2.merge([r,g,b]) # switch it to rgb
plt.imshow(rgb_img)
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
while True:
k = cv2.waitKey(0) & 0xFF # 0xFF? To get the lowest byte.
if k == 27: break # Code for the ESC key
cv2.destroyAllWindows()
No comments:
Post a Comment