File: ipl2qimage.py

package info (click to toggle)
pymecavideo 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,996 kB
  • sloc: python: 4,604; xml: 881; makefile: 134
file content (127 lines) | stat: -rw-r--r-- 3,819 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
from __future__ import print_function
licence = {}
licence['en'] = """
    pymecavideo version %s:

    a program to track moving points in a video frameset

    Copyright (C) 2007-2008 Jean-Baptiste Butet <ashashiwa@gmail.com>

    Copyright (C) 2007-2008 Georges Khaznadar <georgesk@ofset.org>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

licence['fr'] = u"""
    pymecavideo version %s :

    un programme pour tracer les trajectoires des points dans une vidéo.

    Copyright (C) 2007-2008 Jean-Baptiste Butet <ashashiwa@gmail.com>

    Copyright (C) 2007-2008 Georges Khaznadar <georgesk@ofset.org>

    Ce projet est un logiciel libre : vous pouvez le redistribuer, le modifier selon les terme de la GPL (GNU Public License) dans les termes de la Free Software Foundation concernant la version 3 ou plus de la dite licence.

    Ce programme est fait avec l'espoir qu'il sera utile mais SANS AUCUNE GARANTIE. Lisez la licence pour plus de détails.

    <http://www.gnu.org/licenses/>.
"""

import cv
from PyQt5.QtGui import *

import Image


def IPLtoPIL(cv_image, swap=True, mode="RGB"):
    """
    converts :class:`IPLImage` to :class:`PILImage`.
    :param cv_image: Input image
    :type cv_image:  :class:`IPLImage`
    :param swap: switch RGB/BGR option
    :type swap: bool
    :param mode: color mode
    :type mode: string

    :return: output image
    :rtype: PILImage

    """

    # swaps RGB/BGR

    if (swap):
        copy_image = cv.CreateImage(cv.GetSize(cv_image), cv_image.depth,
                                    cv_image.nChannels)
        cv.CvtColor(cv_image, copy_image, cv.CV_RGB2BGR)
    else:
        copy_image = cv_image
    return Image.fromstring(mode, cv.GetSize(copy_image), copy_image.tostring())


def IPLtoQPixmap(cv_image, swap=True, mode="RGB"):
    """
    converts :class:`IPLImage` to :class:`QPixmap`.
    :param cv_image: input image
    :type cv_image: :class:`IPLImage`
    :param swap: switch RGB/BGR option
    :type swap: bool
    :param mode: color mode
    :type mode: string

    :return: output image

    :rtype: :class:`QPixmap`

    """

    PILstring = IPLtoPIL(cv_image, swap).convert(mode).tostring()
    qimg = QImage(PILstring,
                  cv_image.width,
                  cv_image.height,
                  cv_image.width * 3,
                  QImage.Format_RGB888)
    pixmap = QPixmap.fromImage(qimg)
    print (pixmap.size())
    return pixmap


def PILtoQPixmap(pil_image, swap=True, encoder="jpeg", mode="RGB"):
    """
    converts :class:`PILImage` to :class:`QPixmap`.

    :param cv_image: input image
    :type cv_image: :class:`PILImage`
    :param swap: switch RGB/BGR option
    :type swap: bool
    :param mode: color mode
    :type mode: string

    :return: output image

    :rtype: :class:`QPixmap`.

    """
    # print pil_image
    PILstring = pil_image.convert(mode).tostring()
    #print ("#########",pil_image.size[1], pil_image.size[0])
    qimg = QImage(PILstring,
                  pil_image.size[0],
                  pil_image.size[1],
                  pil_image.size[0] * 3,
                  QImage.Format_RGB888)
    pixmap = QPixmap.fromImage(qimg)
    return pixmap