Пример #1
0
def hsvProceed(img):
    single = cv.CreateImage(cv.GetSize(img), 8, 1)
    single_c = cv.CreateImage(cv.GetSize(img), 8, 1)
    width = 0
    height = 0
    while (1):
        while (1):
            if (img[height, width][0] >
                    70) and (img[height, width][0] <
                             95) and (img[height, width][1] > 53) and (
                                 img[height, width][1] <
                                 230):  #and(img[height,width][2]<200):
                single[height, width] = 255
                single_c[height, width] = 255
            else:
                single[height, width] = 0
                single_c[height, width] = 0
            height = height + 1
            if (height == 480):
                height = 0
                break
        width = width + 1
        if (width == 640):
            break
    cv.Erode(single, single)
    cv.Dilate(single, single)
    cv.Erode(single_c, single_c)
    cv.Dilate(single_c, single_c)
    # cv.ShowImage("rgb",single)
    # cv.WaitKey()
    return single, single_c
Пример #2
0
    def detect_no_draw(self, img):
        # allocate temporary images
        gray = cv.CreateImage((img.width, img.height), 8, 1)
        small_img = cv.CreateImage((cv.Round(img.width / self.image_scale),
                                    cv.Round(img.height / self.image_scale)),
                                   8, 1)

        # convert color input image to grayscale
        cv.CvtColor(img, gray, cv.CV_BGR2GRAY)

        # scale input image for faster processing
        cv.Resize(gray, small_img, cv.CV_INTER_LINEAR)
        cv.EqualizeHist(small_img, small_img)

        if self.cascade:
            t = cv.GetTickCount()
            faces = cv.HaarDetectObjects(small_img, self.cascade,
                                         cv.CreateMemStorage(0),
                                         self.haar_scale, self.min_neighbors,
                                         self.haar_flags, self.min_size)
            t = cv.GetTickCount() - t
        if faces:
            return True
        else:
            return False
Пример #3
0
    def __init__(self, threshold=1, doRecord=True, showWindows=True):
        self.writer = None
        self.font = None
        self.doRecord = doRecord  # Either or not record the moving object
        self.show = showWindows  # Either or not show the 2 windows
        self.frame = None

        self.capture = cv.CaptureFromCAM(0)
        self.frame = cv.QueryFrame(
            self.capture)  # Take a frame to init recorder
        if doRecord:
            self.initRecorder()
        self.gray_frame = cv.CreateImage(cv.GetSize(self.frame),
                                         cv.IPL_DEPTH_8U, 1)
        self.average_frame = cv.CreateImage(cv.GetSize(self.frame),
                                            cv.IPL_DEPTH_32F, 3)
        self.absdiff_frame = None
        self.previous_frame = None

        self.surface = self.frame.width * self.frame.height
        self.currentsurface = 0
        self.currentcontours = None
        self.threshold = threshold
        self.isRecording = False
        self.trigger_time = 0  # Hold timestamp of the last detection
        if showWindows:
            cv.NamedWindow("Image")
            cv.CreateTrackbar("Detection treshold: ", "Image", self.threshold,
                              100, self.onThresholdChange)
Пример #4
0
def hsvProceed(img, camID):
    single = cv.CreateImage(cv.GetSize(img), 8, 1)
    single_c = cv.CreateImage(cv.GetSize(img), 8, 1)
    if camID == 0:
        v_min = 120
    if camID == 1:
        v_min = 100
    width = 0
    height = 0
    while (1):
        while (1):
            if (img[height, width][0] >
                    95) and (img[height, width][0] <
                             140) and (img[height, width][1] > 40) and (
                                 img[height, width][1] <
                                 220) and (img[height, width][2] > v_min):
                single[height, width] = 255.0
                single_c[height, width] = 255.0
            else:
                single[height, width] = 0.0
                single_c[height, width] = 0.0
            height = height + 1
            if (height == 480):
                height = 0
                break
        width = width + 1
        if (width == 640):
            break
    cv.Erode(single, single)
    cv.Dilate(single, single)
    # cv.Erode(single_c, single_c)
    # cv.Dilate(single_c, single_c)
    # cv.ShowImage("rgb",single)
    # cv.WaitKey()
    return single, single_c
Пример #5
0
def getIris(frame):
	iris = []
	copyImg = cv.CloneImage(frame)
	resImg = cv.CloneImage(frame)
	grayImg = cv.CreateImage(cv.GetSize(frame), 8, 1)
	mask = cv.CreateImage(cv.GetSize(frame), 8, 1)
	storage = cv.CreateMat(frame.width, 1, cv.CV_32FC3)
	cv.CvtColor(frame,grayImg,cv.CV_BGR2GRAY)
	cv.Canny(grayImg, grayImg, 5, 70, 3)
	cv.Smooth(grayImg,grayImg,cv.CV_GAUSSIAN, 7, 7)
	circles = getCircles(grayImg)
	iris.append(resImg)
	for circle in circles:
		rad = int(circle[0][2])
		global radius
		radius = rad
		cv.Circle(mask, centroid, rad, cv.CV_RGB(255,255,255), cv.CV_FILLED)
		cv.Not(mask,mask)
		cv.Sub(frame,copyImg,resImg,mask)
		x = int(centroid[0] - rad)
		y = int(centroid[1] - rad)
		w = int(rad * 2)
		h = w
		cv.SetImageROI(resImg, (x,y,w,h))
		cropImg = cv.CreateImage((w,h), 8, 3)
		cv.Copy(resImg,cropImg)
		cv.ResetImageROI(resImg)
		return(cropImg)
	return (resImg)
Пример #6
0
def getthresholdedimg(im):
    imghsv = cv.CreateImage(cv.GetSize(im), 8, 3)
    # Convert image from RGB to HSV
    cv.CvtColor(im, imghsv, cv.CV_BGR2HSV)
    imgthreshold = cv.CreateImage(cv.GetSize(im), 8, 1)
    cv.InRangeS(imghsv, cv.Scalar(23, 100, 100), cv.Scalar(25, 255, 255),
                imgthreshold)  # catch the orange yellow blob
    return imgthreshold
Пример #7
0
def hsvProceed(img, camID):  #img为一三通道的HSV图像,camID
    #初始化
    v_min = 0
    h_max = 0
    h_min = 0
    s_max = 0
    s_min = 0
    width = 0
    height = 0
    #创建两个单通道图像
    single = cv2.CreateImage(cv2.GetSize(img), 8, 1)
    single_c = cv2.CreateImage(cv2.GetSize(img), 8, 1)
    #为不同的摄像头分别设置h,s,v的阈值区间
    if camID == 0:
        v_min = 120
        h_max = 138
        h_min = 95
        s_max = 256
        s_min = 30
    if camID == 1:
        v_min = 10
        h_max = 140
        h_min = 95
        s_max = 256
        s_min = 30

# 提取红色部分到single,组建单通道图像

    while (1):
        while (1):
            if (img[height, width][0] >=
                    h_min) and (img[height, width][0] < h_max) and (
                        img[height, width][1] >=
                        s_min) and (img[height, width][1] < s_max) and (
                            img[height, width][2] >= v_min):  #筛选红色部分
                single[height, width] = 255.0
                single_c[height, width] = 255.0
            else:
                single[height, width] = 0.0
                single_c[height, width] = 0.0
            height = height + 1
            if (height == 480):
                height = 0
                break
        width = width + 1
        if (width == 640):
            break
#形态学处理
    cv2.Erode(single, single)
    cv2.Dilate(single, single)

    return single, single_c
Пример #8
0
    def run(self):
        while True:
            img = self.capture.read()

            #blur the source image to reduce color noise
            cv2.blur(img, img, 3)

            #convert the image to hsv(Hue, Saturation, Value) so its
            #easier to determine the color to track(hue)
            hsv_img = cv2.CreateImage(cv2.GetSize(img), 8, 3)
            cv2.CvtColor(img, hsv_img, cv2.CV_BGR2HSV)

            #limit all pixels that don't match our criteria, in this case we are
            #looking for purple but if you want you can adjust the first value in
            #both turples which is the hue range(120,140).  OpenCV uses 0-180 as
            #a hue range for the HSV color model
            greenLower = (20, 190, 165)
            greenUpper = (30, 225, 220)
            thresholded_img = cv2.CreateImage(cv2.GetSize(hsv_img), 8, 1)
            cv2.InRangeS(hsv_img, greenLower, greenUpper, thresholded_img)

            #determine the objects moments and check that the area is large
            #enough to be our object
            moments = cv2.Moments(thresholded_img, 0)
            area = cv2.GetCentralMoment(moments, 0, 0)

            #there can be noise in the video so ignore objects with small areas
            if (area > 100000):
                #determine the x and y coordinates of the center of the object
                #we are tracking by dividing the 1, 0 and 0, 1 moments by the area
                x = cv2.GetSpatialMoment(moments, 1, 0) / area
                y = cv2.GetSpatialMoment(moments, 0, 1) / area

                #print 'x: ' + str(x) + ' y: ' + str(y) + ' area: ' + str(area)

                #create an overlay to mark the center of the tracked object
                overlay = cv2.CreateImage(cv2.GetSize(img), 8, 3)

                cv2.Circle(overlay, (x, y), 2, (255, 255, 255), 20)
                cv2.Add(img, overlay, img)
                #add the thresholded image back to the img so we can see what was
                #left after it was applied
                cv2.Merge(thresholded_img, None, None, None, img)

            #display the image
            cv2.ShowImage(color_tracker_window, img)

            if cv2.WaitKey(10) == 27:
                break
  def __produce_gradient_image(self, i, scale):
    size = cv.GetSize(i)
    grey_image = cv.CreateImage(size, 8, 1)

    size = [s/scale for s in size]
    grey_image_small = cv.CreateImage(size, 8, 1)

    cv.CvtColor(i, grey_image, cv.CV_RGB2GRAY)

    df_dx = cv.CreateImage(cv.GetSize(i), cv.IPL_DEPTH_16S, 1)
    cv.Sobel( grey_image, df_dx, 1, 1)
    cv.Convert(df_dx, grey_image)
    cv.Resize(grey_image, grey_image_small)#, interpolation=cv.CV_INTER_NN)
    cv.Resize(grey_image_small, grey_image)#, interpolation=cv.CV_INTER_NN)
    return grey_image
  def show_shapes(shapes):
    """ Function to show all of the shapes which are passed to it
    """
    cv.NamedWindow("Shape Model", cv.CV_WINDOW_AUTOSIZE)
    # Get size for the window
    max_x = int(max([pt.x for shape in shapes for pt in shape.pts]))
    max_y = int(max([pt.y for shape in shapes for pt in shape.pts]))
    min_x = int(min([pt.x for shape in shapes for pt in shape.pts]))
    min_y = int(min([pt.y for shape in shapes for pt in shape.pts]))

    i = cv.CreateImage((max_x-min_x+20, max_y-min_y+20), cv.IPL_DEPTH_8U, 3)
    cv.Set(i, (0, 0, 0))
    for shape in shapes:
      r = randint(0, 255)
      g = randint(0, 255)
      b = randint(0, 255)
      #r = 0
      #g = 0
      #b = 0
      for pt_num, pt in enumerate(shape.pts):
        # Draw normals
        #norm = shape.get_normal_to_point(pt_num)
        #cv.Line(i,(pt.x-min_x,pt.y-min_y), \
        #    (norm[0]*10 + pt.x-min_x, norm[1]*10 + pt.y-min_y), (r, g, b))
        cv.Circle(i, (int(pt.x-min_x), int(pt.y-min_y)), 2, (r, g, b), -1)
    cv.ShowImage("Shape Model",i)
def find_leds(thresh_img):
    """
    Given a binary image showing the brightest pixels in an image, 
    returns a result image, displaying found leds in from PIL import Image
a rectangle
    """
    contours = cv2.FindContours(thresh_img,
                                cv2.CreateMemStorage(),
                                mode=cv2.CV_RETR_EXTERNAL,
                                method=cv2.CV_CHAIN_APPROX_NONE,
                                offset=(0, 0))

    regions = []
    while contours:
        pts = [pt for pt in contours]
        x, y = zip(*pts)
        min_x, min_y = min(x), min(y)
        width, height = max(x) - min_x + 1, max(y) - min_y + 1
        regions.append((min_x, min_y, width, height))
        contours = contours.h_next()

        out_img = cv2.CreateImage(cv2.GetSize(grey_img), 8, 3)
    for x, y, width, height in regions:
        pt1 = x, y
        pt2 = x + width, y + height
        color = (0, 0, 255, 0)
        cv2.Rectangle(out_img, pt1, pt2, color, 2)

    return out_img, regions
def extract_bright(grey_img, histogram=False):
    """
    Extracts brightest part of the image.
    Expected to be the LEDs (provided that there is a dark background)
    Returns a Thresholded image
    histgram defines if we use the hist calculation to find the best margin
    """
    ## Searches for image maximum (brightest pixel)
    # We expect the LEDs to be brighter than the rest of the image
    [minVal, maxVal, minLoc, maxLoc] = cv2.MinMaxLoc(grey_img)
    print "Brightest pixel val is %d" % (maxVal)

    #We retrieve only the brightest part of the image
    # Here is use a fixed margin (80%), but you can use hist to enhance this one
    if 0:
        ## Histogram may be used to wisely define the margin
        # We expect a huge spike corresponding to the mean of the background
        # and another smaller spike of bright values (the LEDs)
        hist = grey_histogram(img, nBins=64)
        [hminValue, hmaxValue, hminIdx, hmaxIdx] = cv2.GetMinMaxHistValue(hist)
        margin = 0  # statistics to be calculated using hist data
    else:
        margin = 0.8

    thresh = int(maxVal * margin)  # in pix value to be extracted
    print "Threshold is defined as %d" % (thresh)

    thresh_img = cv2.CreateImage(cv2.GetSize(img), img.depth, 1)
    cv2.Threshold(grey_img, thresh_img, thresh, 255, cv2.CV_THRESH_BINARY)

    return thresh_img
Пример #13
0
    def detect_faces(self, image_filename):
        """ Detects all faces and returns a list with
                images and corresponding coordinates"""

        logging.debug(
            'Start method "detect_faces" for file %s (face-detector.py)' %
            image_filename)
        cascade = cv.Load(parameter.cascadefile)  # load face cascade
        image = cv.LoadImage(image_filename)  # loads and converts image

        # detect and save coordinates of detected faces
        coordinates = cv.HaarDetectObjects(
            image, cascade, cv.CreateMemStorage(), parameter.scaleFactor,
            parameter.minNeighbors, parameter.flags, parameter.min_facesize)

        # Convert to greyscale - better results when converting AFTER facedetection with viola jones
        if image.channels == 3:
            logging.debug(
                'Bild %s wird in Graustufenbild umgewandelt (face-detector.py)'
                % image_filename)
            grey_face = (cv.CreateImage((image.width, image.height), 8,
                                        1))  # Create grey-scale Image
            cv.CvtColor(image, grey_face, cv.CV_RGB2GRAY
                        )  # convert Image to Greyscale (necessary for SURF)
            image = grey_face

        logging.debug(
            '%d faces successfully detected in file %s (face-detector.py)' %
            (len(coordinates), image_filename))
        return image, coordinates
Пример #14
0
def maxValueGarylize(image):
    grayimg = cv2.CreateImage(cv2.GetSize(image), image.depth, 1)
    for i in range(image.height):
        for j in range(image.width):
            grayimg[i, j] = max(image[i, j][0], image[i, j][1], image[i, j][2])
#    cv.ShowImage('srcImage', image)
    cv2.ShowImage('maxGrayImage', grayimg)
Пример #15
0
    def found_face(self):
        # global frame_copy
        if (not self.camera_is_on()) or (not self.find_face_is_on()):
            return False

        self.flushCameraBuffer()  # this reduces the frame delay
        frame = cv.QueryFrame(self.capture)
        if frame is None:
            self.close_camera()
            return False

        if not frame:
            cv.WaitKey(0)
        if not self.frame_copy:
            self.frame_copy = cv.CreateImage((frame.width, frame.height),
                                             cv.IPL_DEPTH_8U, frame.nChannels)

        if frame.origin == cv.IPL_ORIGIN_TL:
            cv.Copy(frame, self.frame_copy)
        else:
            cv.Flip(frame, self.frame_copy, 0)

        if self.showVideo:
            result = self.detect_and_draw(self.frame_copy)
        else:
            result = self.detect_no_draw(self.frame_copy)
        cv.WaitKey(10)
        return result
Пример #16
0
def getPolar2CartImg(image, rad):
	imgSize = cv.GetSize(image)
	c = (float(imgSize[0]/2.0), float(imgSize[1]/2.0))
	imgRes = cv.CreateImage((rad*3, int(360)), 8, 3)
	#cv.LogPolar(image,imgRes,c,50.0, cv.CV_INTER_LINEAR+cv.CV_WARP_FILL_OUTLIERS)
	cv.LogPolar(image,imgRes,c,60.0, cv.CV_INTER_LINEAR+cv.CV_WARP_FILL_OUTLIERS)
	return (imgRes)
Пример #17
0
def scanner_procces(frame, set_zbar):
    set_width = 100.0 / 100
    set_height = 90.0 / 100

    coord_x = int(frame.width * (1 - set_width) / 2)
    coord_y = int(frame.height * (1 - set_height) / 2)
    width = int(frame.width * set_width)
    height = int(frame.height * set_height)

    get_sub = cv.GetSubRect(frame,
                            (coord_x + 1, coord_y + 1, width - 1, height - 1))

    cv.Rectangle(frame, (coord_x, coord_y),
                 (coord_x + width, coord_y + height), (255, 0, 0))

    cm_im = cv.CreateImage((get_sub.width, get_sub.height), cv.IPL_DEPTH_8U, 1)
    cv.ConvertImage(get_sub, cm_im)
    image = zbar.Image(cm_im.width, cm_im.height, 'Y800', cm_im.tostring())

    set_zbar.scan(image)
    for symbol in image:
        print '\033[1;32mResult : %s symbol "%s" \033[1;m' % (symbol.type,
                                                              symbol.data)

    cv.ShowImage("webcame", frame)
    #cv.ShowImage("webcame2", get_sub)
    cv.WaitKey(10)
Пример #18
0
def DetectFace(image, faceCascade):
    #modified from: http://www.lucaamore.com/?p=638

    min_size = (20, 20)
    image_scale = 1
    haar_scale = 1.1
    min_neighbors = 3
    haar_flags = 0

    # Allocate the temporary images
    smallImage = cv2.CreateImage((cv2.Round(
        image.width / image_scale), cv2.Round(image.height / image_scale)), 8,
                                 1)

    # Scale input image for faster processing
    cv2.Resize(image, smallImage, cv2.CV_INTER_LINEAR)

    # Equalize the histogram
    cv2.EqualizeHist(smallImage, smallImage)

    # Detect the faces
    faces = cv2.HaarDetectObjects(smallImage, faceCascade,
                                  cv2.CreateMemStorage(0), haar_scale,
                                  min_neighbors, haar_flags, min_size)

    # If faces are found
    if faces:
        for ((x, y, w, h), n) in faces:
            # the input to cv.HaarDetectObjects was resized, so scale the
            # bounding box of each face and convert it to two CvPoints
            pt1 = (int(x * image_scale), int(y * image_scale))
            pt2 = (int((x + w) * image_scale), int((y + h) * image_scale))
            cv2.Rectangle(image, pt1, pt2, cv2.RGB(255, 0, 0), 5, 8, 0)

    return image
Пример #19
0
    def __init__(self, S1, S2):
        den = 2
        self.width = S1 / den
        self.height = S2 / den

        self.sg = cv2.CreateImage((self.width, self.height), 8, 3)
        self.sgc = cv.CreateImage((self.width, self.height), 8, 3)
        self.hsv = cv.CreateImage((self.width, self.height), 8, 3)
        self.dst2 = cv.CreateImage((self.width, self.height), 8, 1)
        self.d = cv.CreateImage((self.width, self.height), cv.IPL_DEPTH_16S, 1)
        self.d2 = cv.CreateImage((self.width, self.height), 8, 1)
        self.b = cv.CreateImage((self.width, self.height), 8, 1)

        self.lastdetected = 0
        self.THR = 70
        self.dects = 50  # ideal number of number of lines detections

        self.hue = cv.CreateImage((self.width, self.height), 8, 1)
        self.sat = cv.CreateImage((self.width, self.height), 8, 1)
        self.val = cv.CreateImage((self.width, self.height), 8, 1)

        # stores the coordinates that make up the face. in order: p,p1,p3,p2 (i.e.) counterclockwise winding
        self.prevface = [(0, 0), (5, 0), (0, 5)]
        self.dodetection = True
        self.onlyBlackCubes = False

        self.succ = 0  # number of frames in a row that we were successful in finding the outline
        self.tracking = False
        self.win_size = 5
        self.flags = 0
        self.detected = 0

        self.grey = cv.CreateImage((self.width, self.height), 8, 1)
        self.prev_grey = cv.CreateImage((self.width, self.height), 8, 1)
        self.pyramid = cv.CreateImage((self.width, self.height), 8, 1)
        self.prev_pyramid = cv.CreateImage((self.width, self.height), 8, 1)

        self.ff = cv.InitFont(cv.CV_FONT_HERSHEY_PLAIN, 1, 1, shear=0, thickness=1, lineType=8)

        self.undetectednum = 100
        self.extract = False
        self.selected = 0
        self.colors = [[] for i in range(6)]
        self.center_pixels = [[] for i in range(6)]
        self.hsvs = [[] for i in range(6)]
        self.assigned = [[-1 for i in range(9)] for j in range(6)]

        for i in range(6):
            self.assigned[i][4] = i

        self.didassignments = False

        # Used only for visualization purposes
        self.mycols = [(0, 127, 255),   # orange
                       (20, 240, 20),   # green
                       (0, 0, 255),     # red
                       (200, 0, 0),     # blue
                       (0, 255, 255),   # yellow
                       (255, 255, 255)] # white
Пример #20
0
 def _build_image(self, frame):
     if not self._frame:
         self._frame = cv2.CreateImage((frame.width, frame.height), cv.IPL_DEPTH_8U, frame.nChannels)
     if frame.origin == cv2.IPL_ORIGIN_TL:
         cv2.Copy(frame, self._frame)
     else:
         cv2.Flip(frame, self._frame, 0)
     return IplQImage(self._frame)
Пример #21
0
def weightedAverageValueGary(image):
    grayimg = cv2.CreateImage(cv2.GetSize(image), image.depth, 1)
    for i in range(image.height):
        for j in range(image.width):
            grayimg[i, j] = 0.3 * image[i, j][0] + 0.59 * image[
                i, j][1] + 0.11 * image[i, j][2]
#    cv2.ShowImage('srcImage', image)
    cv2.ShowImage('weightedGrayImage', grayimg)
Пример #22
0
def averageValueGary(image):
    grayimg = cv2.CreateImage(cv2.GetSize(image), image.depth, 1)
    for i in range(image.height):
        for j in range(image.width):
            grayimg[i,
                    j] = (image[i, j][0] + image[i, j][1] + image[i, j][2]) / 3
#    cv2.ShowImage('srcImage', image)
    cv2.ShowImage('averageGrayImage', grayimg)
Пример #23
0
    def applyEffect(self, image, width, height):
        ipl_img = cv2.cv.CreateImageHeader((image.shape[1], image.shape[0]), cv.IPL_DEPTH_8U, 3)
        cv2.cv.SetData(ipl_img, image.tostring(), image.dtype.itemsize * 3 * image.shape[1])

        gray = cv.CreateImage((width, height), 8, 1)  # tuple as the first arg

        dst_img = cv.CreateImage(cv.GetSize(ipl_img), cv.IPL_DEPTH_8U, 3)  # _16S  => cv2.cv.iplimage
        if self.effect == 'dilate':
            cv.Dilate(ipl_img, dst_img, None, 5)
        elif self.effect == 'laplace':
            cv.Laplace(ipl_img, dst_img, 3)
        elif self.effect == 'smooth':
            cv.Smooth(ipl_img, dst_img, cv.CV_GAUSSIAN)
        elif self.effect == 'erode':
            cv.Erode(ipl_img, dst_img, None, 1)

        cv.Convert(dst_img, ipl_img)
        return self.ipl2tk_image(dst_img)
def to_gray(img):
    """
    Converts the input in grey levels
    Returns a one channel image
    """
    grey_img = cv2.CreateImage(cv2.GetSize(img), img.depth, 1)
    cv2.CvtColor(img, grey_img, cv2.CV_RGB2GRAY)

    return grey_img
Пример #25
0
def get_hands(image):
    """ Returns the hand as white on black. Uses value in HSV to determine
        hands."""
    size = cv2.GetSize(image)
    hsv = cv2.CreateImage(size, 8, 3)
    hue = cv2.CreateImage(size, 8, 1)
    sat = cv2.CreateImage(size, 8, 1)
    val = cv2.CreateImage(size, 8, 1)
    hands = cv2.CreateImage(size, 8, 1)
    cv2.Cv2tColor(image, hsv, cv2.CV2_BGR2HSV)
    cv2.Split(hsv, hue, sat, val, None)

    cv2.ShowImage('Live', image)
    cv2.ShowImage('Hue', hue)
    cv2.ShowImage('Saturation', sat)

    cv2.Threshold(
        hue, hue, 10, 255,
        cv2.CV2_THRESH_TOZERO)  #set to 0 if <= 10, otherwise leave as is
    cv2.Threshold(
        hue, hue, 244, 255,
        cv2.CV2_THRESH_TOZERO_INV)  #set to 0 if > 244, otherwise leave as is
    cv2.Threshold(hue, hue, 0, 255,
                  cv2.CV2_THRESH_BINARY_INV)  #set to 255 if = 0, otherwise 0
    cv2.Threshold(
        sat, sat, 64, 255,
        cv2.CV2_THRESH_TOZERO)  #set to 0 if <= 64, otherwise leave as is
    cv2.EqualizeHist(sat, sat)

    cv2.Threshold(sat, sat, 64, 255,
                  cv2.CV2_THRESH_BINARY)  #set to 0 if <= 64, otherwise 255

    cv2.ShowImage('Saturation threshold', sat)
    cv2.ShowImage('Hue threshold', hue)

    cv2.Mul(hue, sat, hands)

    #smooth + threshold to filter noise
    #    cv2.Smooth(hands, hands, smoothtype=cv2.CV2_GAUSSIAN, param1=13, param2=13)
    #    cv2.Threshold(hands, hands, 200, 255, cv2.CV2_THRESH_BINARY)

    cv2.ShowImage('Hands', hands)

    return hands
Пример #26
0
def Restore(mat):
    w = mat.cols
    h = mat.rows
    size = (w,h)
    iRestore = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
    for i in range(h):
        for j in range(w):
            num = -1 if (i+j)%2 == 1 else 1
            iRestore[i,j] = mat[i,j][0]*num/(w*h)
    return iRestore
 def draw_model_fitter(f):
   cv.NamedWindow("Model Fitter", cv.CV_WINDOW_AUTOSIZE)
   # Copy image
   i = cv.CreateImage(cv.GetSize(f.image), f.image.depth, 3)
   cv.Copy(f.image, i)
   for pt_num, pt in enumerate(f.shape.pts):
     # Draw normals
     cv.Circle(i, (int(pt.x), int(pt.y)), 2, (0,0,0), -1)
   cv.ShowImage("Shape Model",i)
   cv.WaitKey()
Пример #28
0
def display_rgb(dev, data, timestamp):
    global keep_running
    cv.Image = frame_convert.video_cv(data)
    img = cv.CreateImage(cv.GetSize(cv.Image), cv.IPL_DEPTH_16S, 3)
    cv.ShowImage('RGB', cv.Image)
    for x in range(1, 5):
        name = "img%d" % (x)
        cv.SaveImage('name.png', cv.Image)
        time.sleep(1)
    if cv.WaitKey(10) == 27:
        keep_running = False
Пример #29
0
    def detect_and_draw(self, img):

        # allocate temporary images
        gray = cv.CreateImage((img.width, img.height), 8, 1)
        small_img = cv.CreateImage((cv.Round(img.width / self.image_scale),
                                    cv.Round(img.height / self.image_scale)),
                                   8, 1)

        # convert color input image to grayscale
        cv.CvtColor(img, gray, cv.CV_BGR2GRAY)

        # scale input image for faster processing
        cv.Resize(gray, small_img, cv.CV_INTER_LINEAR)
        cv.EqualizeHist(small_img, small_img)

        if self.cascade:
            t = cv.GetTickCount()
            faces = cv.HaarDetectObjects(small_img, self.cascade,
                                         cv.CreateMemStorage(0),
                                         self.haar_scale, self.min_neighbors,
                                         self.haar_flags, self.min_size)
            t = cv.GetTickCount() - t
            #		print "time taken for detection = %gms" % (t/(cv.GetTickFrequency()*1000.))
            if faces:
                face_found = True

                for ((x, y, w, h), n) in faces:
                    # the input to cv.HaarDetectObjects was resized, so scale the
                    # bounding box of each face and convert it to two CvPoints
                    pt1 = (int(x * self.image_scale),
                           int(y * self.image_scale))
                    pt2 = (int((x + w) * self.image_scale),
                           int((y + h) * self.image_scale))
                    cv.Rectangle(img, pt1, pt2, cv.RGB(255, 0, 0), 3, 8, 0)
            else:
                face_found = False

        cv.ShowImage("video", img)
        return face_found
Пример #30
0
def FImage(mat):
    w = mat.cols
    h = mat.rows
    size = (w,h)
    # iReal = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
    # iIma = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
    iAdd = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
    for i in range(h):
        for j in range(w):
            # iReal[i,j] = mat[i,j][0]/h
            # iIma[i,j] = mat[i,j][1]/h
            iAdd[i,j] = mat[i,j][1]/h + mat[i,j][0]/h
    return iAdd