Пример #1
0
    def process(self, videofile, progress):
        progress(0, _("Extracting histogram"))
        video = hg.cvCreateFileCapture(str(videofile).encode(sys.getfilesystemencoding()))
        if not video:
            raise Exception("Could not open video file")
        histo = cv.cvCreateHist([256],cv.CV_HIST_ARRAY,[[0,256]], 1)
        frame = hg.cvQueryFrame(video)
        frame_gray  = cv.cvCreateImage(cv.cvGetSize(frame), frame.depth, 1);
        hists    = []
        nbframes = 0

        fps = hg.cvGetCaptureProperty(video, hg.CV_CAP_PROP_FPS)
        while frame :
            if not progress(hg.cvGetCaptureProperty(video, hg.CV_CAP_PROP_POS_AVI_RATIO)):
                break
            hg.cvConvertImage(frame,frame_gray)
            cv.cvCalcHist(frame_gray,histo,0,None)
            h = [cv.cvGetReal1D(histo.bins,i) for i in range(255) ]
            h = numpy.array(h,dtype='int32')
            hists.append(h)
            frame = hg.cvQueryFrame(video)
            nbframes += 1

        hists = numpy.array(hists)
        return hists.reshape(nbframes, -1), fps
Пример #2
0
	def run(self):

		if self.capture:
			webcam_frame = highgui.cvQueryFrame( self.capture )
		else:
			print "Capture failed!"
			return

		if self.inverted_video.get_active():
			highgui.cvConvertImage(webcam_frame, webcam_frame, highgui.CV_CVTIMG_FLIP)
		highgui.cvConvertImage(webcam_frame, self.display_frame, highgui.CV_CVTIMG_SWAP_RB)




		if False:
			# PROCESS WEBCAM FRAME HERE...
			inputImage = cv.cvCreateImage(cv.cvGetSize(webcam_frame), cv.IPL_DEPTH_8U, 1)
			cv.cvCvtColor(webcam_frame, inputImage, cv.CV_RGB2GRAY);

			cv.cvThreshold(inputImage, inputImage, 128, 255, cv.CV_THRESH_BINARY)

			mysize = cv.cvGetSize(webcam_frame)
			height = mysize.height
			width = mysize.width


			# Find horizontal first-moment:
			if False:
				mysum = 0
				for i in range(height):
					mysum += sum(inputImage[i,:])

				print "Sum:", mysum

			cv.cvMerge( inputImage, inputImage, inputImage, None, self.display_frame )




		incoming_pixbuf = gtk.gdk.pixbuf_new_from_data(
				self.display_frame.imageData,
				gtk.gdk.COLORSPACE_RGB,
				False,
				8,
				self.display_frame.width,
				self.display_frame.height,
				self.display_frame.widthStep)
		incoming_pixbuf.copy_area(0, 0, self.display_frame.width, self.display_frame.height, self.webcam_pixbuf, 0, 0)

		self.video_image.queue_draw()


		return self.video_enabled_button.get_active()
Пример #3
0
    def run(self):

        if self.capture:
            webcam_frame = highgui.cvQueryFrame(self.capture)
        else:
            print "Capture failed!"
            return

        if self.inverted_video.get_active():
            highgui.cvConvertImage(webcam_frame, webcam_frame,
                                   highgui.CV_CVTIMG_FLIP)
        highgui.cvConvertImage(webcam_frame, self.display_frame,
                               highgui.CV_CVTIMG_SWAP_RB)

        if False:
            # PROCESS WEBCAM FRAME HERE...
            inputImage = cv.cvCreateImage(cv.cvGetSize(webcam_frame),
                                          cv.IPL_DEPTH_8U, 1)
            cv.cvCvtColor(webcam_frame, inputImage, cv.CV_RGB2GRAY)

            cv.cvThreshold(inputImage, inputImage, 128, 255,
                           cv.CV_THRESH_BINARY)

            mysize = cv.cvGetSize(webcam_frame)
            height = mysize.height
            width = mysize.width

            # Find horizontal first-moment:
            if False:
                mysum = 0
                for i in range(height):
                    mysum += sum(inputImage[i, :])

                print "Sum:", mysum

            cv.cvMerge(inputImage, inputImage, inputImage, None,
                       self.display_frame)

        incoming_pixbuf = gtk.gdk.pixbuf_new_from_data(
            self.display_frame.imageData, gtk.gdk.COLORSPACE_RGB, False, 8,
            self.display_frame.width, self.display_frame.height,
            self.display_frame.widthStep)
        incoming_pixbuf.copy_area(0, 0, self.display_frame.width,
                                  self.display_frame.height,
                                  self.webcam_pixbuf, 0, 0)

        self.video_image.queue_draw()

        return self.video_enabled_button.get_active()
Пример #4
0
@author: martin
'''
import opencv.cv as cv
import opencv.highgui as hg
import webcamera
import util as ut    



if __name__ == '__main__':
    
    wc = webcamera.Webcamera()
    img = wc.get_frame()
    grey = cv.cvCreateImage((img.width, img.height), 8,1)
    hg.cvConvertImage(img, grey)
    
#    img = hg.cvLoadImage('test.jpg')
#    grey = cv.cvCreateImage((img.width, img.height), 8,1)
#    hg.cvConvertImage(img, grey)
    
    file = open('test.raw', 'wb')
    

    
    for i in range(grey.height):
        for j in range(grey.width):
            file.write(chr(grey[i][j]))
            
    file.close()
    
Пример #5
0
'''
Created on Oct 12, 2009

@author: martin
'''
import opencv.cv as cv
import opencv.highgui as hg
import webcamera
import util as ut

if __name__ == '__main__':

    wc = webcamera.Webcamera()
    img = wc.get_frame()
    grey = cv.cvCreateImage((img.width, img.height), 8, 1)
    hg.cvConvertImage(img, grey)

    #    img = hg.cvLoadImage('test.jpg')
    #    grey = cv.cvCreateImage((img.width, img.height), 8,1)
    #    hg.cvConvertImage(img, grey)

    file = open('test.raw', 'wb')

    for i in range(grey.height):
        for j in range(grey.width):
            file.write(chr(grey[i][j]))

    file.close()

    #ut.display_images([img])