python - cv2 aliasing issue

asked 2018-03-20 16:00:45 -0500

trimalcione gravatar image

updated 2018-03-21 03:34:23 -0500

I'm playing videos with this piece of code:

class Player(threading.Thread):
def __init__(self, video):
    self.config = Conf.Conf() = video
    self.cap = cv2.VideoCapture(video)
    self.frameTitle = self.config.SOFTWARE_TITLE + self.config.VERSION

def run(self):
        ret, frame =
        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.cap.set(cv2.CAP_PROP_POS_FRAMES, 0)

def Stop(self):

def ClosePlayer(self):

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.

edit retag flag offensive close merge delete


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 simple StretchBlt() 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.

berak gravatar imageberak ( 2018-03-21 01:23:22 -0500 )edit

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.

trimalcione gravatar imagetrimalcione ( 2018-03-21 03:28:38 -0500 )edit

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 !

berak gravatar imageberak ( 2018-03-21 04:58:16 -0500 )edit

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.

trimalcione gravatar imagetrimalcione ( 2018-03-21 05:22:00 -0500 )edit

heh, true. but you can use setWindowPos() to move it "out of sight".

berak gravatar imageberak ( 2018-03-21 05:27:39 -0500 )edit

Yes, tried it but it feels "buggy"

trimalcione gravatar imagetrimalcione ( 2018-03-21 07:23:12 -0500 )edit