python - cv2 aliasing issue
I'm playing videos with this piece of code:
class Player(threading.Thread):
def __init__(self, video):
threading.Thread.__init__(self)
self.config = Conf.Conf()
self.video = video
self.cap = cv2.VideoCapture(video)
self.frameTitle = self.config.SOFTWARE_TITLE + self.config.VERSION
def run(self):
while(self.cap.isOpened()):
ret, frame = self.cap.read()
if ret:
cv2.namedWindow(self.frameTitle, cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(self.frameTitle, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow(self.frameTitle, frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
self.Stop()
self.ClosePlayer()
else:
self.cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
def Stop(self):
self.cap.release()
def ClosePlayer(self):
cv2.destroyAllWindows()
Now, my problem is that videos loose quality and it seems like there's aliasing on smooth shapes. As seen in this picture.
This code is working on a Win10 machine with Python 2.7 (32-bit) and cv2 version 3.4.0.
Edit: I can see correctly videos if I play them on VLC or Windows Media Player. See this pic for infos on the videos I'm working with.
cv2.WND_PROP_FULLSCREEN
means, your image will get scaled to window size. and it is not even opencv doing that, but the win32 ui (a simpleStretchBlt()
is used there).the vlc folks might be doing something more clever there, and if you want to build a video player, use their code (it's all scriptable via lua !) not opencv.
Thank you very much for your reply. I prefer not using an external software as I need to include all in one package and not having an external software as a video player, thank you anyway for your solution. Hope I could find the time to contribute to solve this issue one day.
one thing you could try is: don't use any of those
FULLSCREEN
flags, but resize your frames manually to desired fullscreen (with an appropriate interpolation flag like INTER_CUBIC)expensive, but will look nicer !
Thank you for your support, really precious. Now the problem is that I see the status bar of the window and I'd like to hide that. With FULLSCREEN settings all the GUI of the window is hidden.
heh, true. but you can use
setWindowPos()
to move it "out of sight".Yes, tried it but it feels "buggy"