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


Python cv.CreateImage方法代码示例

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


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

示例1: rotate

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.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: __init__

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def __init__(self):
        self.norm_rgb=np.zeros((config.height,config.width,3),np.uint8)
        self.dst=np.zeros((config.height,config.width),np.uint8)
        self.b=0
        self.g=0
        self.r=0
        
        self.lb=0
        self.lg=0
        self.lr=0
        
        self.m=np.zeros((config.height,config.width),np.uint8)
        #self.win=cv2.namedWindow("detect")
        #self.dst=cv.CreateImage((config.width,config.height),8,1)
        
        #cv2.createTrackbar("blue", "detect",0,255,self.change_b)
        #cv2.createTrackbar("green","detect",0,255,self.change_g)
        #cv2.createTrackbar("red","detect",0,255,self.change_r)
        
        #cv2.createTrackbar("low_blue", "detect",0,255,self.change_lb)
        #cv2.createTrackbar("low_green","detect",0,255,self.change_lg)
        #cv2.createTrackbar("low_red","detect",0,255,self.change_lr) 
开发者ID:akash0x53,项目名称:virtual-dressing-room,代码行数:24,代码来源:Tshirt.py

示例3: hue_histogram_as_image

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def hue_histogram_as_image(self, hist):
        """ Returns a nice representation of a hue histogram """

        histimg_hsv = cv.CreateImage( (320,200), 8, 3)

        mybins = cv.CloneMatND(hist.bins)
        cv.Log(mybins, mybins)
        (_, hi, _, _) = cv.MinMaxLoc(mybins)
        cv.ConvertScale(mybins, mybins, 255. / hi)

        w,h = cv.GetSize(histimg_hsv)
        hdims = cv.GetDims(mybins)[0]
        for x in range(w):
            xh = (180 * x) / (w - 1)  # hue sweeps from 0-180 across the image
            val = int(mybins[int(hdims * x / w)] * h / 255)
            cv.Rectangle( histimg_hsv, (x, 0), (x, h-val), (xh,255,64), -1)
            cv.Rectangle( histimg_hsv, (x, h-val), (x, h), (xh,255,255), -1)

        histimg = cv.CreateImage( (320,200), 8, 3)
        cv.CvtColor(histimg_hsv, histimg, cv.CV_HSV2BGR)
        return histimg 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:23,代码来源:camshift.py

示例4: gen_image

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.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

示例5: resize

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.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

示例6: crop

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.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

示例7: image_data_as_rgb

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.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

示例8: enable_alpha

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.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

示例9: unhideImage

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def unhideImage(self):
        width = int(self.readBits(16),2) #Read 16bits and convert it in int
        height = int(self.readBits(16),2)
        unhideimg = cv.CreateImage((width,height), 8, 3) #Create an image in which we will put all the pixels read
        for h in range(height):
            for w in range(width):
                for chan in range(unhideimg.channels):
                    val = list(unhideimg[h,w])
                    val[chan] = int(self.readByte(),2) #Read the value
                    unhideimg[h,w] = tuple(val)
        return unhideimg 
开发者ID:ahhh,项目名称:Stego_Dropper,代码行数:13,代码来源:LSBSteg.py

示例10: doGreyscaleProcessor

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def doGreyscaleProcessor(self, img):
		(x, y, w, h) = self.frame.rect
		bw = cv.CreateImage((w, h), 8, 1)
		cv.CvtColor(img, bw, cv.CV_RGB2GRAY)
		return bw 
开发者ID:starstuffharvestingstarlight,项目名称:tcg-ocr-scanner,代码行数:7,代码来源:tcg_ocr_scanner.py

示例11: __init__

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def __init__(self,threshold=25, 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.capture=cv.CaptureFromFile('crash-480.mp4')
        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.onChange) 
开发者ID:alduxvm,项目名称:rpi-opencv,代码行数:30,代码来源:motion-detection.py

示例12: getImage

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def getImage(self):
        """
        **SUMMARY**

        Retrieve an Image-object from the camera.  If you experience problems
        with stale frames from the camera's hardware buffer, increase the flushcache
        number to dequeue multiple frames before retrieval

        We're working on how to solve this problem.

        **RETURNS**

        A SimpleCV Image from the camera.

        **EXAMPLES**

        >>> cam = Camera()
        >>> while True:
        >>>    cam.getImage().show()

        """

        if self.pygame_camera:
            return Image(self.pygame_buffer.copy())

        if (not self.threaded):
            cv.GrabFrame(self.capture)
            self.capturetime = time.time()
        else:
            self.capturetime = self._threadcapturetime

        frame = cv.RetrieveFrame(self.capture)
        newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
        cv.Copy(frame, newimg)
        return Image(newimg, self) 
开发者ID:sightmachine,项目名称:SimpleCV2,代码行数:37,代码来源:Camera.py

示例13: detect_and_draw

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.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)

    cv.ShowImage("result", img) 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:31,代码来源:facedetect.py

示例14: __init__

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def __init__(self, src_image):
        self.src_image = src_image
        self.dst_image = cv.CloneMat(src_image)
        self.hist_image = cv.CreateImage((320, 200), 8, 1)
        self.hist = cv.CreateHist([hist_size], cv.CV_HIST_ARRAY, ranges, 1)

        self.brightness = 0
        self.contrast = 0

        cv.NamedWindow("image", 0)
        cv.NamedWindow("histogram", 0)
        cv.CreateTrackbar("brightness", "image", 100, 200, self.update_brightness)
        cv.CreateTrackbar("contrast", "image", 100, 200, self.update_contrast)

        self.update_brightcont() 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:17,代码来源:demhist.py

示例15: process_image

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import CreateImage [as 别名]
def process_image(self, slider_pos):
        """
        This function finds contours, draws them and their approximation by ellipses.
        """
        stor = cv.CreateMemStorage()

        # Create the destination images
        image02 = cv.CloneImage(self.source_image)
        cv.Zero(image02)
        image04 = cv.CreateImage(cv.GetSize(self.source_image), cv.IPL_DEPTH_8U, 3)
        cv.Zero(image04)

        # Threshold the source image. This needful for cv.FindContours().
        cv.Threshold(self.source_image, image02, slider_pos, 255, cv.CV_THRESH_BINARY)

        # Find all contours.
        cont = cv.FindContours(image02,
            stor,
            cv.CV_RETR_LIST,
            cv.CV_CHAIN_APPROX_NONE,
            (0, 0))

        for c in contour_iterator(cont):
            # Number of points must be more than or equal to 6 for cv.FitEllipse2
            if len(c) >= 6:
                # Copy the contour into an array of (x,y)s
                PointArray2D32f = cv.CreateMat(1, len(c), cv.CV_32FC2)
                for (i, (x, y)) in enumerate(c):
                    PointArray2D32f[0, i] = (x, y)

                # Draw the current contour in gray
                gray = cv.CV_RGB(100, 100, 100)
                cv.DrawContours(image04, c, gray, gray,0,1,8,(0,0))

                # Fits ellipse to current contour.
                (center, size, angle) = cv.FitEllipse2(PointArray2D32f)

                # Convert ellipse data from float to integer representation.
                center = (cv.Round(center[0]), cv.Round(center[1]))
                size = (cv.Round(size[0] * 0.5), cv.Round(size[1] * 0.5))

                # Draw ellipse in random color
                color = cv.CV_RGB(random.randrange(256),random.randrange(256),random.randrange(256))
                cv.Ellipse(image04, center, size,
                          angle, 0, 360,
                          color, 2, cv.CV_AA, 0)

        # Show image. HighGUI use.
        cv.ShowImage( "Result", image04 ) 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:51,代码来源:fitellipse.py


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