Dear Sirs

I am using a videorecorder program that uses the imageqt.py library . This
library calls the import of pyqt that i didnt have because i use pyside. I
change the call for using pyside and the sintax of the init instruction
(pyside qimage object uses diferent parameter list). The problem is that
when i try to use it i can“t see the video i receive only a black square.
Can you help me ?? i send you the two py files.

Thanks
Dardo
#!/usr/bin/python
##############################################################################
# This script will take webcam shots and save notes into files
##############################################################################
#    webcamNotebook is a small quick and dirty script which will allow the user
#         to make quick and dirty memos with webcam shots
#
#    Copyright (C) 2010  Juhapekka Piiroinen
#
#    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/>.
#
#############################################################################
# Contact: juhapekka.piiroi...@gmail.com
# Version: 0.1
#############################################################################
from VideoCapture import Device
import VideoCapture
from time import strftime
import ImageQt
import sys
import time
from PySide import QtGui,QtCore
import os

fol = strftime("%Y-%m-%d_%H%M%S")
os.mkdir(fol)
os.chdir(fol)

class WebcamPreview(QtGui.QLabel):
        def __init__(self,parent=None):
                QtGui.QLabel.__init__(self,parent)
                self.cam = Device()
                self.cam.setResolution(640,480)
                self.timer = QtCore.QTimer()
                self.timer.setInterval(40)
                self.connect(self.timer,QtCore.SIGNAL('timeout()'),self.refresh)
                self.timer.start()
                self.imageCounter = 0
        
        def refresh(self):
                self.repaint()

        def save(self,filename="image.jpg"):
                self.imageCounter += 1
                if (filename=="image.jpg"):
                        filename = "image.%s.jpg" % self.imageCounter
                self.cam.saveSnapshot(filename,timestamp=1)
                self.repaint()
                return filename
                
        def paintEvent(self,event):
                paint = QtGui.QPainter()
                img = ImageQt.ImageQt(self.cam.getImage(timestamp=1))
                paint.begin(self)
                paint.drawImage(0,0,img)
                paint.end()

class WebcamNotebook(QtGui.QWidget):
        def __init__(self, parent=None):
                QtGui.QWidget.__init__(self, parent)
                self.setWindowTitle('Quick-and-Dirty(tm) - Webcam Notebook')
                self.snapshot_scrollarea = QtGui.QScrollArea() 
                self.snapshot_scrollarea.setWidgetResizable(True)
                
self.snapshot_scrollarea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
                self.snapshot_scrollarea.setLayout(QtGui.QVBoxLayout())
                self.snapshot_scrollarea.setMinimumSize(150,480)
                self.snapshot = QtGui.QWidget()
                self.snapshot.setLayout(QtGui.QVBoxLayout())
                self.snapshot_scrollarea.setWidget(self.snapshot)
                hbox = QtGui.QHBoxLayout()
                hbox.addWidget(self.snapshot_scrollarea)
                
                vbox = QtGui.QVBoxLayout()
                self.plainText = QtGui.QPlainTextEdit()
                vbox.addWidget(self.plainText)
                btnWebcamShot = QtGui.QPushButton('Take Webcam Shot / Save Note 
/ Start New One')
                vbox.addWidget(btnWebcamShot)
                
                self.webcamPreview = WebcamPreview()
                self.webcamPreview.setMinimumSize(640,480)
                vbox.addWidget(self.webcamPreview)
                
                hbox.addLayout(vbox)
                
                self.setLayout(hbox)
                
                self.connect(btnWebcamShot, 
QtCore.SIGNAL('clicked()'),self.HandleTakeWebcamShot)


        def HandleTakeWebcamShot(self):
                filename = self.webcamPreview.save()
                f = open("%s.txt" % filename,"w")
                f.write(self.plainText.toPlainText())
                f.close()
                fnotes = open("notes.html","a")
                fnotes.write("<hr /><p><img src='%s' /><br />%s</p>" % 
(filename,self.plainText.toPlainText()))
                fnotes.close()
                pixmap = QtGui.QPixmap(filename)
                label = QtGui.QLabel()
                label.setPixmap(pixmap.scaledToWidth(100))
                
                label.setToolTip("Image: %s<hr />Notes:<br />%s" % 
(filename,self.plainText.toPlainText()))
                label.setMinimumSize(100,100)
                self.snapshot.layout().addWidget(label)
                self.plainText.clear()
                
app = QtGui.QApplication(sys.argv)
webNote = WebcamNotebook()
time.sleep(4)
webNote.show()
sys.exit(app.exec_())
#
# The Python Imaging Library.
# $Id$
#
# a simple Qt image interface.
#
# history:
# 2006-06-03 fl: created
# 2006-06-04 fl: inherit from QImage instead of wrapping it
# 2006-06-05 fl: removed toimage helper; move string support to ImageQt
#
# Copyright (c) 2006 by Secret Labs AB
# Copyright (c) 2006 by Fredrik Lundh
#
# See the README file for information on usage and redistribution.
#

import Image

from PySide.QtGui import QImage, qRgb

##
# (Internal) Turns an RGB color into a Qt compatible color integer.

def rgb(r, g, b):
    # use qRgb to pack the colors, and then turn the resulting long
    # into a negative integer with the same bitpattern.
    return (qRgb(r, g, b) & 0xffffff) - 0x1000000

##
# An PIL image wrapper for Qt.  This is a subclass of PyQt4's QImage
# class.
#
# @param im A PIL Image object, or a file name (given either as Python
#     string or a PyQt string object).

class ImageQt(QImage):

    def __init__(self, im):

        data = None
        colortable = None

        # handle filename, if given instead of image name
        if hasattr(im, "toUtf8"):
            # FIXME - is this really the best way to do this?
            im = unicode(im.toUtf8(), "utf-8")
        if Image.isStringType(im):
            im = Image.open(im)

        if im.mode == "1":
            format = QImage.Format_Mono
        elif im.mode == "L":
            format = QImage.Format_Indexed8
            colortable = []
            for i in range(256):
                colortable.append(rgb(i, i, i))
        elif im.mode == "P":
            format = QImage.Format_Indexed8
            colortable = []
            palette = im.getpalette()
            for i in range(0, len(palette), 3):
                colortable.append(rgb(*palette[i:i+3]))
        elif im.mode == "RGB":
            data = im.tostring("raw", "BGRX")
            format = QImage.Format_RGB32
        elif im.mode == "RGBA":
            try:
                data = im.tostring("raw", "BGRA")
            except SystemError:
                # workaround for earlier versions
                r, g, b, a = im.split()
                im = Image.merge("RGBA", (b, g, r, a))
            format = QImage.Format_ARGB32
        else:
            raise ValueError("unsupported image mode %r" % im.mode)

        # must keep a reference, or Qt will crash!
        self.__data = data or im.tostring()

#       QImage.__init__(self, self.__data, im.size[0], im.size[1], format)
        QImage.__init__(self, im.size[0], im.size[1], format)        

        if colortable:
            self.setColorTable(colortable)
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to