UsingNet / nvjpeg-python

nvjpeg for python
MIT License
93 stars 24 forks source link

To decode images immediately into the desired format #7

Open SalimMaxHigh opened 3 years ago

SalimMaxHigh commented 3 years ago

Hey! Thanks for a great library for decoding images. I would like to know if there is a possibility to decode images immediately into the desired format. For example in gray, such as in OpenCV: cv2.imdecode(some_image, cv2.IMREAD_GRAYSCALE).

zeng-qinghui commented 3 years ago

Thanks for using.

If you want to get a gray image. You can try:

from nvjpeg import NvJpeg 
import numpy as np
nj = NvJpeg()
nv_img = nj.read(YOUR_IMG_PATH).dot([0.114,0.587,0.299]).astype(np.uint8)
cv2.imshow("GrayImg", nv_img)
cv2.waitKey(0)