예제 #1
0
                              random.randrange (0, 5) * 0.1,
                              random.randrange (0, 10),
                              line_type)

        cv.cvPutText (image, "Testing text rendering!",
                      pt1, font,
                      random_color (random))
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # prepare a text, and get it's properties
    font = cv.cvInitFont (cv.CV_FONT_HERSHEY_COMPLEX,
                          3, 3, 0.0, 5, line_type)
    text_size, ymin = cv.cvGetTextSize ("OpenCV forever!", font)
    pt1.x = (width - text_size.width) / 2
    pt1.y = (height + text_size.height) / 2
    image2 = cv.cvCloneImage(image)

    # now, draw some OpenCV pub ;-)
    for i in range (255):
        cv.cvSubS (image2, cv.cvScalarAll (i), image, None)
        cv.cvPutText (image, "OpenCV forever!",
                      pt1, font, cv.cvScalar (255, i, i))
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # wait some key to end
    highgui.cvWaitKey (0)

예제 #2
0
            # 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
            color = hsv2rgb(i * 180. / hdims)

            # draw the rectangle in the wanted color
            cv.cvRectangle(histimg, cv.cvPoint(i * bin_w, histimg.height),
                           cv.cvPoint((i + 1) * bin_w, histimg.height - val),
                           color, -1, 8, 0)
        # Make the sweet negative selection box
        if mouse_select_object and mouse_selection.width > 0 and mouse_selection.height > 0:
            a = cv.cvGetSubRect(frame, mouse_selection)
            cv.cvXorS(a, cv.cvScalarAll(255),
                      a)  # Take the negative of the image..
            del a

        # Carry out the histogram tracking...
        if track_object != 0:
            cv.cvInRangeS(hsv, cv.cvScalar(0, smin, min(vmin, vmax), 0),
                          cv.cvScalar(180, 256, max(vmin, vmax), 0), mask)
            cv.cvSplit(hsv, hue, None, None, None)

            if track_object < 0:
                # Calculate the histogram for the mouse_selection box
                hue_roi_rect = cv.cvGetSubRect(hue, mouse_selection)
                mask_roi_rect = cv.cvGetSubRect(mask, mouse_selection)
                cv.cvCalcHist(hue_roi_rect, obj_hist, 0, mask_roi_rect)
                min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue(
예제 #3
0
            cv.cvEllipseBox(image, track_box, cv.CV_RGB(255,0,0), 3, cv.CV_AA, 0)
            
            if (track_box.size.width > 10 or track_box.size.height  > 10):

                rotate = ( (image.width/2.0) - track_box.center.x) / (image.width/2.0)
                translate = ((image.height/2.0) - track_box.center.y) / (image.height/2.0)
                
                #print "rotate =", rotate, "translate =", translate
                
                if go:
                    move(translate, rotate)
        
        if select_object and selection.width > 0 and selection.height > 0:
            subimg = cv.cvGetSubRect(image, selection)
            cv.cvXorS( subimage, cv.cvScalarAll(255), subimage, 0 )

        highgui.cvShowImage( "VisualJoystick", image )

        c = highgui.cvWaitKey(10)
        if c == '\x1b':
            break        
        elif c == 'b':
            backproject_mode ^= 1
        elif c == 'c':
            track_object = 0
            cv.cvZero( histimg )
            if go:
                stop()

if go:
예제 #4
0
파일: cam-histo.py 프로젝트: Foued70/pycam
            # 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
            color = hsv2rgb (i * 180. / hdims)

            # draw the rectangle in the wanted color
            cv.cvRectangle (histimg,
                            cv.cvPoint (i * bin_w, histimg.height),
                            cv.cvPoint ((i + 1) * bin_w, histimg.height - val),
                            color, -1, 8, 0)
        # Make the sweet negative selection box
        if mouse_select_object and mouse_selection.width > 0 and mouse_selection.height > 0:
            a = cv.cvGetSubRect(frame,mouse_selection)
            cv.cvXorS(a,cv.cvScalarAll(255), a)   # Take the negative of the image..
            del a

        # Carry out the histogram tracking...
        if track_object != 0:            
            cv.cvInRangeS( hsv, cv.cvScalar(0,smin ,min(vmin, vmax), 0), cv.cvScalar(180, 256, max(vmin,vmax), 0), mask )
            cv.cvSplit(hsv, hue, None, None, None)
            
            if track_object < 0:
                # Calculate the histogram for the mouse_selection box
                hue_roi_rect = cv.cvGetSubRect( hue, mouse_selection )
                mask_roi_rect = cv.cvGetSubRect( mask, mouse_selection )
                cv.cvCalcHist (hue_roi_rect, obj_hist, 0, mask_roi_rect)
                min_val, max_val, min_idx, max_idx = cv.cvGetMinMaxHistValue (obj_hist)
                
                track_window = mouse_selection
예제 #5
0
def compute_saliency(image):
    global thresh
    global scale
    saliency_scale = int(math.pow(2,scale));
    bw_im1 = cv.cvCreateImage(cv.cvGetSize(image), cv.IPL_DEPTH_8U,1)
    cv.cvCvtColor(image, bw_im1, cv.CV_BGR2GRAY)
    bw_im = cv.cvCreateImage(cv.cvSize(saliency_scale,saliency_scale), cv.IPL_DEPTH_8U,1)
    cv.cvResize(bw_im1, bw_im)
    highgui.cvShowImage("BW", bw_im)
    realInput = cv.cvCreateImage( cv.cvGetSize(bw_im), cv.IPL_DEPTH_32F, 1);
    imaginaryInput = cv.cvCreateImage( cv.cvGetSize(bw_im), cv.IPL_DEPTH_32F, 1);
    complexInput = cv.cvCreateImage( cv.cvGetSize(bw_im), cv.IPL_DEPTH_32F, 2);

    cv.cvScale(bw_im, realInput, 1.0, 0.0);
    cv.cvZero(imaginaryInput);
    cv.cvMerge(realInput, imaginaryInput, None, None, complexInput);

    dft_M = saliency_scale #cv.cvGetOptimalDFTSize( bw_im.height - 1 );
    dft_N = saliency_scale #cv.cvGetOptimalDFTSize( bw_im.width - 1 );

    dft_A = cv.cvCreateMat( dft_M, dft_N, cv.CV_32FC2 );
    image_Re = cv.cvCreateImage( cv.cvSize(dft_N, dft_M), cv.IPL_DEPTH_32F, 1);
    image_Im = cv.cvCreateImage( cv.cvSize(dft_N, dft_M), cv.IPL_DEPTH_32F, 1);

    # copy A to dft_A and pad dft_A with zeros
    tmp = cv.cvGetSubRect( dft_A, cv.cvRect(0,0, bw_im.width, bw_im.height));
    cv.cvCopy( complexInput, tmp, None );
    if(dft_A.width > bw_im.width):
        tmp = cv.cvGetSubRect( dft_A, cv.cvRect(bw_im.width,0, dft_N - bw_im.width, bw_im.height));
        cv.cvZero( tmp );
    
    cv.cvDFT( dft_A, dft_A, cv.CV_DXT_FORWARD, complexInput.height );
    cv.cvSplit( dft_A, image_Re, image_Im, None, None );
    
    # Compute the phase angle 
    image_Mag = cv.cvCreateImage(cv.cvSize(dft_N, dft_M), cv.IPL_DEPTH_32F, 1);
    image_Phase = cv.cvCreateImage(cv.cvSize(dft_N, dft_M), cv.IPL_DEPTH_32F, 1);
    

    #compute the phase of the spectrum
    cv.cvCartToPolar(image_Re, image_Im, image_Mag, image_Phase, 0)

    log_mag = cv.cvCreateImage(cv.cvSize(dft_N, dft_M), cv.IPL_DEPTH_32F, 1);
    cv.cvLog(image_Mag, log_mag)
    #Box filter the magnitude, then take the difference
    image_Mag_Filt = cv.cvCreateImage(cv.cvSize(dft_N, dft_M), cv.IPL_DEPTH_32F, 1);
    filt = cv.cvCreateMat(3,3, cv.CV_32FC1);
    cv.cvSet(filt,cv.cvScalarAll(-1.0/9.0))
    cv.cvFilter2D(log_mag, image_Mag_Filt, filt, cv.cvPoint(-1,-1))

    cv.cvAdd(log_mag, image_Mag_Filt, log_mag, None)
    cv.cvExp(log_mag, log_mag)
    cv.cvPolarToCart(log_mag, image_Phase, image_Re, image_Im,0);

    cv.cvMerge(image_Re, image_Im, None, None, dft_A)
    cv.cvDFT( dft_A, dft_A, cv.CV_DXT_INVERSE, complexInput.height)
            
    tmp = cv.cvGetSubRect( dft_A, cv.cvRect(0,0, bw_im.width, bw_im.height));
    cv.cvCopy( tmp, complexInput, None );
    cv.cvSplit(complexInput, realInput, imaginaryInput, None, None)
    min, max = cv.cvMinMaxLoc(realInput);
    #cv.cvScale(realInput, realInput, 1.0/(max-min), 1.0*(-min)/(max-min));
    cv.cvSmooth(realInput, realInput);
    threshold = thresh/100.0*cv.cvAvg(realInput)[0]
    cv.cvThreshold(realInput, realInput, threshold, 1.0, cv.CV_THRESH_BINARY)
    tmp_img = cv.cvCreateImage(cv.cvGetSize(bw_im1),cv.IPL_DEPTH_32F, 1)
    cv.cvResize(realInput,tmp_img)
    cv.cvScale(tmp_img, bw_im1, 255,0)
    return bw_im1
예제 #6
0
            if (track_box.size.width > 10 or track_box.size.height > 10):

                rotate = ((image.width / 2.0) -
                          track_box.center.x) / (image.width / 2.0)
                translate = ((image.height / 2.0) -
                             track_box.center.y) / (image.height / 2.0)

                #print "rotate =", rotate, "translate =", translate

                if go:
                    move(translate, rotate)

        if select_object and selection.width > 0 and selection.height > 0:
            subimg = cv.cvGetSubRect(image, selection)
            cv.cvXorS(subimage, cv.cvScalarAll(255), subimage, 0)

        highgui.cvShowImage("VisualJoystick", image)

        c = highgui.cvWaitKey(10)
        if c == '\x1b':
            break
        elif c == 'b':
            backproject_mode ^= 1
        elif c == 'c':
            track_object = 0
            cv.cvZero(histimg)
            if go:
                stop()

if go:
예제 #7
0
                              random.randrange (0, 100) * 0.05 + 0.01,
                              random.randrange (0, 5) * 0.1,
                              random.randrange (0, 10),
                              line_type)

        cv.cvPutText (image, "Testing text rendering!",
                      pt1, font,
                      random_color (random))
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # prepare a text, and get it's properties
    font = cv.cvInitFont (cv.CV_FONT_HERSHEY_COMPLEX,
                          3, 3, 0.0, 5, line_type)
    text_size, ymin = cv.cvGetTextSize ("OpenCV forever!", font)
    pt1.x = (width - text_size.width) / 2
    pt1.y = (height + text_size.height) / 2
    image2 = cv.cvCloneImage(image)

    # now, draw some OpenCV pub ;-)
    for i in range (255):
        cv.cvSubS (image2, cv.cvScalarAll (i), image, None)
        cv.cvPutText (image, "OpenCV forever!",
                      pt1, font, cv.cvScalar (255, i, i))
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # wait some key to end
    highgui.cvWaitKey (0)