当前位置: 首页>>代码示例>>Python>>正文


Python cv.CreateImage方法代码示例

本文整理汇总了Python中cv.CreateImage方法的典型用法代码示例。如果您正苦于以下问题:Python cv.CreateImage方法的具体用法?Python cv.CreateImage怎么用?Python cv.CreateImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv的用法示例。


在下文中一共展示了cv.CreateImage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rotate

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def rotate(self, degrees):
        if (degrees > 180):
            # Flip around both axes
            cv.Flip(self.image, None, -1)
            degrees = degrees - 180

        img = self.image
        size = cv.GetSize(img)

        if (degrees / 90 % 2):
            new_size = (size[1], size[0])
            center = ((size[0] - 1) * 0.5, (size[0] - 1) * 0.5)
        else:
            new_size = size
            center = ((size[0] - 1) * 0.5, (size[1] - 1) * 0.5)

        mapMatrix = cv.CreateMat(2, 3, cv.CV_64F)
        cv.GetRotationMatrix2D(center, degrees, 1.0, mapMatrix)
        dst = cv.CreateImage(new_size, self.image_depth, self.image_channels)
        cv.SetZero(dst)
        cv.WarpAffine(img, dst, mapMatrix)
        self.image = dst 
开发者ID:thumbor,项目名称:opencv-engine,代码行数:24,代码来源:engine.py

示例2: gen_image

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def gen_image(self, size, color_value):
        img0 = cv.CreateImage(size, self.image_depth, self.image_channels)
        if color_value == 'transparent':
            color = (255, 255, 255, 255)
        else:
            color = self.parse_hex_color(color_value)
            if not color:
                raise ValueError('Color %s is not valid.' % color_value)
        cv.Set(img0, color)
        return img0 
开发者ID:thumbor,项目名称:opencv-engine,代码行数:12,代码来源:engine.py

示例3: resize

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def resize(self, width, height):
        thumbnail = cv.CreateImage(
            (int(round(width, 0)), int(round(height, 0))),
            self.image_depth,
            self.image_channels
        )
        cv.Resize(self.image, thumbnail, cv.CV_INTER_AREA)
        self.image = thumbnail 
开发者ID:thumbor,项目名称:opencv-engine,代码行数:10,代码来源:engine.py

示例4: crop

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def crop(self, left, top, right, bottom):
        new_width = right - left
        new_height = bottom - top
        cropped = cv.CreateImage(
            (new_width, new_height), self.image_depth, self.image_channels
        )
        src_region = cv.GetSubRect(self.image, (left, top, new_width, new_height))
        cv.Copy(src_region, cropped)

        self.image = cropped 
开发者ID:thumbor,项目名称:opencv-engine,代码行数:12,代码来源:engine.py

示例5: image_data_as_rgb

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def image_data_as_rgb(self, update_image=True):
        # TODO: Handle other formats
        if self.image_channels == 4:
            mode = 'BGRA'
        elif self.image_channels == 3:
            mode = 'BGR'
        else:
            mode = 'BGR'
            rgb_copy = cv.CreateImage((self.image.width, self.image.height), 8, 3)
            cv.CvtColor(self.image, rgb_copy, cv.CV_GRAY2BGR)
            self.image = rgb_copy
        return mode, self.image.tostring() 
开发者ID:thumbor,项目名称:opencv-engine,代码行数:14,代码来源:engine.py

示例6: enable_alpha

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def enable_alpha(self):
        if self.image_channels < 4:
            with_alpha = cv.CreateImage(
                (self.image.width, self.image.height), self.image_depth, 4
            )
            if self.image_channels == 3:
                cv.CvtColor(self.image, with_alpha, cv.CV_BGR2BGRA)
            else:
                cv.CvtColor(self.image, with_alpha, cv.CV_GRAY2BGRA)
            self.image = with_alpha 
开发者ID:thumbor,项目名称:opencv-engine,代码行数:12,代码来源:engine.py

示例7: detect_and_draw

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def detect_and_draw(img, cascade):
    # allocate temporary images
    gray = cv.CreateImage((img.width,img.height), 8, 1)
    small_img = cv.CreateImage((cv.Round(img.width / image_scale),
			       cv.Round (img.height / 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(cascade):
        t = cv.GetTickCount()
        faces = cv.HaarDetectObjects(small_img, cascade, cv.CreateMemStorage(0),
                                     haar_scale, min_neighbors, haar_flags, min_size)
        t = cv.GetTickCount() - t
        print "detection time = %gms" % (t/(cv.GetTickFrequency()*1000.))
        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))
                cv.Rectangle(img, pt1, pt2, cv.RGB(255, 0, 0), 3, 8, 0)
                print "x= "+str(x)+" y= "+str(y)+" w= "+str(w)+" h= "+str(h)

    cv.ShowImage("Face detection", img) 
开发者ID:alduxvm,项目名称:rpi-opencv,代码行数:32,代码来源:face-detection.py

示例8: process_file

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def process_file(filenameIN, WIDTH = 31, HEIGHT = 31):
    
    print "processing file: "+ filenameIN
    if not (os.path.exists(filenameIN)):
        print "file not found. Aborting."
        return
    else :
        srcImg = cv.LoadImage(filenameIN,0)
        res = cv.CreateImage( (WIDTH, HEIGHT), cv.IPL_DEPTH_8U, 1 )
        cv.Set(res, 255)
        xmin=WIDTH
        xmax=0
        ymin=HEIGHT
        ymax=0
        for i in range(srcImg.width):
            for j in range(srcImg.height):
                #print "xmax"
                #print cv.Get2D(srcImg, j, i)
                if cv.Get2D(srcImg, j, i)[0] == 0.0 :
                    #print "xin"
                    if i<xmin:
                        xmin = i
                    if i>xmax:
                        xmax = i
                    if j<ymin:
                        ymin=j
                    if j>ymax:
                        ymax=j
        
        offsetx = (WIDTH - (xmax-xmin))/2
        offsety = (HEIGHT - (ymax-ymin))/2
        #print 'WIDTH',WIDTH,"offset",offsety,offsetx
        for i in range(xmax-xmin):
            for j in range(ymax-ymin):
                if ((offsety+j>0) and (offsety+j<res.height) and (offsetx+i>0) and (offsetx+i<res.width)):
                    #print "haha"
                    cv.Set2D(res, offsety+j, offsetx+i, cv.Get2D(srcImg, ymin+j, xmin+i))

        cv.SaveImage(filenameIN, res) 
开发者ID:00nanhai,项目名称:captchacker2,代码行数:41,代码来源:characters_center.py

示例9: detect_and_draw

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def detect_and_draw(img):
    t1 = time.time()

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

    # blur the source image to reduce color noise 
    cv.Smooth(img, img, cv.CV_BLUR, 3);
    hsv_img = cv.CreateImage(cv.GetSize(img), 8, 3)
    cv.CvtColor(img, hsv_img, cv.CV_BGR2HSV)
    thresholded_img =  cv.CreateImage(cv.GetSize(hsv_img), 8, 1)
    #cv.InRangeS(hsv_img, (120, 80, 80), (140, 255, 255), thresholded_img)

    # White
    sensitivity = 15
    cv.InRangeS(hsv_img, (0, 0, 255-sensitivity), (255, sensitivity, 255), thresholded_img)

    # Red
    #cv.InRangeS(hsv_img, (0, 150, 0), (5, 255, 255), thresholded_img)

    # Blue
    #cv.InRangeS(hsv_img, (100, 50, 50), (140, 255, 255), thresholded_img)

    # Green
    #cv.InRangeS(hsv_img, (40, 50, 50), (80, 255, 255), thresholded_img)

    mat=cv.GetMat(thresholded_img)
    moments = cv.Moments(mat, 0)
    area = cv.GetCentralMoment(moments, 0, 0)

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

    cv.EqualizeHist(small_img, small_img)

    if(area > 5000):
        #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 = cv.GetSpatialMoment(moments, 1, 0)/area
        y = cv.GetSpatialMoment(moments, 0, 1)/area
        x = int(round(x))
        y = int(round(y))

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

        cv.Circle(overlay, (x, y), 2, (0, 0, 0), 20)
        cv.Add(img, overlay, img)
        #add the thresholded image back to the img so we can see what was  
        #left after it was applied 
        #cv.Merge(thresholded_img, None, None, None, img)
        t2 = time.time()
        message = "Color tracked!"
        print "detection time = %gs x=%d,y=%d" % ( round(t2-t1,3) , x, y)

    cv.ShowImage("Color detection", img) 
开发者ID:alduxvm,项目名称:rpi-opencv,代码行数:60,代码来源:color-2.py

示例10: run

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def run(self):
        while True:
            img = cv.QueryFrame( self.capture )
            t1 = time.time()
            #blur the source image to reduce color noise 
            cv.Smooth(img, img, cv.CV_BLUR, 3);

            #convert the image to hsv(Hue, Saturation, Value) so its  
            #easier to determine the color to track(hue) 
            hsv_img = cv.CreateImage(cv.GetSize(img), 8, 3)
            cv.CvtColor(img, hsv_img, cv.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 
            thresholded_img =  cv.CreateImage(cv.GetSize(hsv_img), 8, 1)

            # White
            sensitivity = 10
            cv.InRangeS(hsv_img, (0, 0, 255-sensitivity), (255, sensitivity, 255), thresholded_img)

            # Red
            #cv.InRangeS(hsv_img, (0, 150, 0), (5, 255, 255), thresholded_img)

            # Blue
            #cv.InRangeS(hsv_img, (100, 50, 50), (140, 255, 255), thresholded_img)

            # Green
            #cv.InRangeS(hsv_img, (40, 50, 50), (80, 255, 255), thresholded_img)

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

            #there can be noise in the video so ignore objects with small areas 
            if(area > 10000):
                #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 = cv.GetSpatialMoment(moments, 1, 0)/area
                y = cv.GetSpatialMoment(moments, 0, 1)/area
                x = int(round(x))
                y = int(round(y))

                #create an overlay to mark the center of the tracked object 
                overlay = cv.CreateImage(cv.GetSize(img), 8, 3)
                cv.Circle(overlay, (x, y), 2, (255, 255, 255), 20)
                cv.Add(img, overlay, img)
                #add the thresholded image back to the img so we can see what was  
                #left after it was applied 
                t2 = time.time()
                cv.Merge(thresholded_img, None, None, None, img)
                print "detection time = %gs x=%d,y=%d" % ( round(t2-t1,3) , x, y)
            
            #display the image  
            cv.ShowImage(color_tracker_window, img)

            if cv.WaitKey(10) == 27:
                break 
开发者ID:alduxvm,项目名称:rpi-opencv,代码行数:63,代码来源:color-1.py

示例11: FPV_thread

# 需要导入模块: import cv [as 别名]
# 或者: from cv import CreateImage [as 别名]
def FPV_thread():
    global camera_index
    global capture
    global WINDOW_NAME
    global latest_frame
    global FPV_thread_stop
    global overlay_message  # shared with application return results
    global face_position    # shared with application return results

    FPV_init()

    cv.NamedWindow(WINDOW_NAME, cv.CV_WINDOW_NORMAL)
    cv.MoveWindow(WINDOW_NAME, 0, 0)

    width_scale = 1.0
    height_scale = 1.0
    while True:
        frame = cv.QueryFrame(capture)
        cv.Flip(frame, None, 1)

        #copy to buffer
        frame_lock.acquire()
        original_imagesize = (0,0)
        resized_imagesize = (0,0)
        if not latest_frame:
            latest_frame = cv.CreateImage((640, 480), frame.depth, frame.nChannels)
            original_imagesize = cv.GetSize(frame)
            resized_imagesize = cv.GetSize(latest_frame)
            width_scale = original_imagesize[0]*1.0/resized_imagesize[0]
            height_scale = original_imagesize[1]*1.0/resized_imagesize[1]
        cv.Resize(frame, latest_frame)
        frame_lock.release()


        #Display Result
        text_start_point = (10, 50)
        cv.PutText(frame, overlay_message, text_start_point, font, cv.Scalar(255,255,255))
        cv.Rectangle(frame, text_start_point, (original_imagesize[0], 100), cv.Scalar(0,0,0), thickness=cv.CV_FILLED)
        if face_position[0] > 0.0:
            point1 = (int(face_position[0]*width_scale), int(face_position[1]*height_scale))
            point2 = (int((face_position[0] + face_position[2])*width_scale), \
                    int((face_position[1]+face_position[3])*height_scale))
            cv.Rectangle(frame, point1, point2, \
                    cv.Scalar(255, 255, 255), thickness=2)
        cv.ShowImage(WINDOW_NAME, frame)
        cv.ResizeWindow(WINDOW_NAME, 200, 100)
        cv.NamedWindow(WINDOW_NAME, cv.CV_WINDOW_NORMAL);
        cv.SetWindowProperty(WINDOW_NAME, 0, cv.CV_WINDOW_FULLSCREEN);
        c = cv.WaitKey(10)
        if c == ord('q'):
            break

    print "[INFO] FPV Thread is finished"
    FPV_thread_stop = True
    FPV_close() 
开发者ID:cmusatyalab,项目名称:elijah-provisioning,代码行数:57,代码来源:FPV_client.py


注:本文中的cv.CreateImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。