Per il progetto Aruco ho provato ad acquisire un fotogramma da una webcam e salvarlo in diversi formati con diverso grado di compressione. Di sotto si riportano i risultati (ingrandire le immagini per vedere gli artefatti di compressione)
import cv2
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FRAME_WIDTH,1280)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT,720)
compression_params = [cv2.IMWRITE_PNG_COMPRESSION, 0]
while True:
return_value,image = camera.read()
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('image',gray)
if cv2.waitKey(1)& 0xFF == ord('s'):
cv2.imwrite('test_0.png',image,[cv2.IMWRITE_PNG_COMPRESSION,0])
cv2.imwrite('test_3.png',image,[cv2.IMWRITE_PNG_COMPRESSION,3])
cv2.imwrite('test_9.png',image,[cv2.IMWRITE_PNG_COMPRESSION,9])
cv2.imwrite('test_100.jpg',image,[cv2.IMWRITE_JPEG_QUALITY,100])
cv2.imwrite('test_060.jpg',image,[cv2.IMWRITE_JPEG_QUALITY,60])
cv2.imwrite('test_060.ppm',image,[cv2.IMWRITE_PXM_BINARY,1])
break
camera.release()
cv2.destroyAllWindows()
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FRAME_WIDTH,1280)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT,720)
compression_params = [cv2.IMWRITE_PNG_COMPRESSION, 0]
while True:
return_value,image = camera.read()
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('image',gray)
if cv2.waitKey(1)& 0xFF == ord('s'):
cv2.imwrite('test_0.png',image,[cv2.IMWRITE_PNG_COMPRESSION,0])
cv2.imwrite('test_3.png',image,[cv2.IMWRITE_PNG_COMPRESSION,3])
cv2.imwrite('test_9.png',image,[cv2.IMWRITE_PNG_COMPRESSION,9])
cv2.imwrite('test_100.jpg',image,[cv2.IMWRITE_JPEG_QUALITY,100])
cv2.imwrite('test_060.jpg',image,[cv2.IMWRITE_JPEG_QUALITY,60])
cv2.imwrite('test_060.ppm',image,[cv2.IMWRITE_PXM_BINARY,1])
break
camera.release()
cv2.destroyAllWindows()
PNG compressione 0 |
PNG compressione 3 |
JPG quality 60 |
JPG quality 100 |
Nessun commento:
Posta un commento