Exemple #1
0
def mask_image( im, mask ):
	if mask.depth == 8:
		bim = cv.cvCreateImage( cv.cvSize(mask.width, mask.height), cv.IPL_DEPTH_32F, mask.nChannels )
		cv.cvConvertScale( mask, bim, 1.0/255.0)

	if im.depth == 8:
		newim = cv.cvCreateImage( cv.cvSize(im.width, im.height), cv.IPL_DEPTH_32F, im.nChannels )
		cv.cvConvertScale( im, newim, 1.0/255.0)

		
	print 'newim.depth = ',newim.depth
	print 'newim.nChannels = ',newim.nChannels
	print 'bim.depth = ',bim.depth
	print 'bim.nChannels = ',bim.nChannels
	if newim.nChannels == 3 and newim.depth == 32 and bim.nChannels == 3 and bim.depth == 32:
		outputIm = cv.cvCloneImage( bim )
		cv.cvMul( bim, newim, outputIm, 1 )
		return outputIm
	else:
		print 'oops problem with formats'
		return mask
Exemple #2
0
def mask_image(im, mask):
    if mask.depth == 8:
        bim = cv.cvCreateImage(cv.cvSize(mask.width, mask.height),
                               cv.IPL_DEPTH_32F, mask.nChannels)
        cv.cvConvertScale(mask, bim, 1.0 / 255.0)

    if im.depth == 8:
        newim = cv.cvCreateImage(cv.cvSize(im.width, im.height),
                                 cv.IPL_DEPTH_32F, im.nChannels)
        cv.cvConvertScale(im, newim, 1.0 / 255.0)

    print 'newim.depth = ', newim.depth
    print 'newim.nChannels = ', newim.nChannels
    print 'bim.depth = ', bim.depth
    print 'bim.nChannels = ', bim.nChannels
    if newim.nChannels == 3 and newim.depth == 32 and bim.nChannels == 3 and bim.depth == 32:
        outputIm = cv.cvCloneImage(bim)
        cv.cvMul(bim, newim, outputIm, 1)
        return outputIm
    else:
        print 'oops problem with formats'
        return mask
Exemple #3
0
def display_images(image_list, max_x=1200, max_y=1000, save_images=False):
    """
	Display a list of OpenCV images tiled across the screen
	with maximum width of max_x and maximum height of max_y

	save_images - will save the images(with timestamp)
	"""

    curtime = time.localtime()
    date_name = time.strftime('%Y_%m_%d_%I%M%S', curtime)

    loc_x, loc_y = 0, 0
    wins = []
    for i, im in enumerate(image_list):
        if save_images:
            if im.nChannels == 1 and im.depth == cv.IPL_DEPTH_32F:
                clr = cv.cvCreateImage(cv.cvSize(im.width, im.height),
                                       cv.IPL_DEPTH_8U, 1)
                cv.cvConvertScale(im, clr, 255.0)
                im = clr
            highgui.cvSaveImage('image%d_' % i + date_name + '.png', im)

        window_name = 'image %d' % i
        wins.append((window_name, im))
        highgui.cvNamedWindow(window_name, highgui.CV_WINDOW_AUTOSIZE)
        highgui.cvMoveWindow(window_name, loc_x, loc_y)
        loc_x = loc_x + im.width
        if loc_x > max_x:
            loc_x = 0
            loc_y = loc_y + im.height
            if loc_y > max_y:
                loc_y = 0
    while True:
        for name, im in wins:
            highgui.cvShowImage(name, im)
        keypress = highgui.cvWaitKey(10)
        if keypress == '\x1b':
            break
Exemple #4
0
def display_images(image_list, max_x = 1200, max_y = 1000, save_images=False):
	"""
	Display a list of OpenCV images tiled across the screen
	with maximum width of max_x and maximum height of max_y

	save_images - will save the images(with timestamp)
	"""

	curtime=time.localtime()
	date_name = time.strftime('%Y_%m_%d_%I%M%S', curtime)

	loc_x, loc_y = 0, 0
	wins = []
	for i, im in enumerate(image_list):
		if save_images:
			if im.nChannels == 1 and im.depth == cv.IPL_DEPTH_32F:
				clr = cv.cvCreateImage(cv.cvSize(im.width, im.height), cv.IPL_DEPTH_8U, 1)
				cv.cvConvertScale(im, clr, 255.0)
				im = clr
			highgui.cvSaveImage('image%d_'%i+date_name+'.png', im)

		window_name = 'image %d' % i
		wins.append((window_name, im)) 
		highgui.cvNamedWindow(window_name, highgui.CV_WINDOW_AUTOSIZE)
		highgui.cvMoveWindow(window_name, loc_x, loc_y)
		loc_x = loc_x + im.width
		if loc_x > max_x:
			loc_x = 0
			loc_y = loc_y + im.height
			if loc_y > max_y:
				loc_y = 0
	while True:
		for name, im in wins:
			highgui.cvShowImage(name, im)
		keypress = highgui.cvWaitKey(10)
		if keypress == '\x1b':
			break
        mask_roi = cv.cvGetSubRect (mask, selection)

        # it's time to compute the histogram
        cv.cvCalcHist (hue_roi, hist, 0, mask_roi)

        # extract the min and max value of the histogram
        min_val, max_val = cv.cvGetMinMaxHistValue (hist, None, None)

        # compute the scale factor
        if max_val > 0:
            scale = 255. / max_val
        else:
            scale = 0.

        # scale the histograms
        cv.cvConvertScale (hist.bins, hist.bins, scale, 0)

        # clear the histogram image
        cv.cvSetZero (histimg)

        # compute the width for each bin do display
        bin_w = histimg.width / hdims
        
        for  i in range (hdims):
            # for all the bins

            # get the value, and scale to the size of the hist image
            val = cv.cvRound (cv.cvGetReal1D (hist.bins, i)
                              * histimg.height / 255)

            # compute the color
Exemple #6
0
def Process(inFile, outFile):
	image1 = highgui.cvLoadImage(inFile,0)
	sz = cv.cvGetSize(image1)
	image2 = cv.cvCreateImage(sz, 8, 1)
	cv.cvConvertScale(image1, image2, 1.2, 0)
	highgui.cvSaveImage(outFile, image2)
Exemple #7
0
                           cv.cvScalar(180, 256, max(_vmin,_vmax),0),
                           mask );

            cv.cvSplit( hsv, hue, None, None, None)

            if track_object < 0:
                max_val = 0.0                
                subhue = cv.cvGetSubRect(hue, selection)
                submask = cv.cvGetSubRect(mask, selection)
                cv.cvCalcHist( subhue, hist, 0, submask )
                
                # extract the min and max value of the histogram
                min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue (hist)
                
                if (max_val):
                    cv.cvConvertScale( hist.bins, hist.bins, 255.0 / max_val, 0)
                else:
                    cv.cvConvertScale( hist.bins, hist.bins, 0.0, 0 )

                track_window = selection
                track_object = 1


            cv.cvCalcArrBackProject( hue, backproject, hist )
            
            cv.cvAnd( backproject, mask, backproject, 0 )
            cv.cvCamShift( backproject, track_window,
                           cv.cvTermCriteria( cv.CV_TERMCRIT_EPS | cv.CV_TERMCRIT_ITER, 10, 1 ),
                           track_comp, track_box )
            track_window = track_comp.rect
            
Exemple #8
0
                          cv.cvScalar(180, 256, max(_vmin, _vmax), 0), mask)

            cv.cvSplit(hsv, hue, None, None, None)

            if track_object < 0:
                max_val = 0.0
                subhue = cv.cvGetSubRect(hue, selection)
                submask = cv.cvGetSubRect(mask, selection)
                cv.cvCalcHist(subhue, hist, 0, submask)

                # extract the min and max value of the histogram
                min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue(
                    hist)

                if (max_val):
                    cv.cvConvertScale(hist.bins, hist.bins, 255.0 / max_val, 0)
                else:
                    cv.cvConvertScale(hist.bins, hist.bins, 0.0, 0)

                track_window = selection
                track_object = 1

            cv.cvCalcArrBackProject(hue, backproject, hist)

            cv.cvAnd(backproject, mask, backproject, 0)
            cv.cvCamShift(
                backproject, track_window,
                cv.cvTermCriteria(cv.CV_TERMCRIT_EPS | cv.CV_TERMCRIT_ITER, 10,
                                  1), track_comp, track_box)
            track_window = track_comp.rect
Exemple #9
-3
        mask_roi = cv.cvGetSubRect(mask, selection)

        # it's time to compute the histogram
        cv.cvCalcHist(hue_roi, hist, 0, mask_roi)

        # extract the min and max value of the histogram
        min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue(hist)

        # compute the scale factor
        if max_val > 0:
            scale = 255. / max_val
        else:
            scale = 0.

        # scale the histograms
        cv.cvConvertScale(hist.bins, hist.bins, scale, 0)

        # clear the histogram image
        cv.cvSetZero(histimg)

        # compute the width for each bin do display
        bin_w = histimg.width / hdims

        for i in range(hdims):
            # for all the bins

            # get the value, and scale to the size of the hist image
            val = cv.cvRound(
                cv.cvGetReal1D(hist.bins, i) * histimg.height / 255)

            # compute the color