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


Python cv.GetSize方法代码示例

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


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

示例1: rotate

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

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

示例3: size

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import GetSize [as 别名]
def size(self):
        return cv.GetSize(self.image) 
开发者ID:thumbor,项目名称:opencv-engine,代码行数:4,代码来源:engine.py

示例4: __init__

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import GetSize [as 别名]
def __init__(self, img):
		(self.max_w, self.max_h) = cv.GetSize(img)
		# rectangle position TODO: use frame detection
		(self.w, self.h) = (350, 30)
		(self.x, self.y) = (self.max_w/2 - self.w/2, 0)
		self.rect = (self.x, self.y, self.w, self.h)
		# TODO: replace with frame specific blocks from db
		self.processors = ['CropProcessor', 'GreyscaleProcessor'] 
开发者ID:starstuffharvestingstarlight,项目名称:tcg-ocr-scanner,代码行数:10,代码来源:tcg_ocr_scanner.py

示例5: __init__

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

示例6: initRecorder

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import GetSize [as 别名]
def initRecorder(self): #Create the recorder
        codec = cv.CV_FOURCC('M', 'J', 'P', 'G')
        self.writer=cv.CreateVideoWriter(datetime.now().strftime("%b-%d_%H_%M_%S")+".mp4", codec, 5, cv.GetSize(self.frame), 1)
        #FPS set to 5 because it seems to be the fps of my cam but should be ajusted to your needs
        self.font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 2, 8) #Creates a font 
开发者ID:alduxvm,项目名称:rpi-opencv,代码行数:7,代码来源:motion-detection.py

示例7: getCurrentFrameAsImage

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import GetSize [as 别名]
def getCurrentFrameAsImage(self):
        im = numpy.array(self.currentFrame)
        im = cv.fromarray(im)
        cv.CvtColor(im, im, cv.CV_BGR2RGB)
        pgImg = pygame.image.frombuffer(im.tostring(), cv.GetSize(im), "RGB")
        return pgImg 
开发者ID:stbnps,项目名称:DanceCV,代码行数:8,代码来源:Input.py

示例8: cvShiftDFT

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import GetSize [as 别名]
def cvShiftDFT(src_arr, dst_arr ):

    size = cv.GetSize(src_arr)
    dst_size = cv.GetSize(dst_arr)

    if dst_size != size:
        cv.Error( cv.CV_StsUnmatchedSizes, "cv.ShiftDFT", "Source and Destination arrays must have equal sizes", __FILE__, __LINE__ )

    if(src_arr is dst_arr):
        tmp = cv.CreateMat(size[1]/2, size[0]/2, cv.GetElemType(src_arr))

    cx = size[0] / 2
    cy = size[1] / 2 # image center

    q1 = cv.GetSubRect( src_arr, (0,0,cx, cy) )
    q2 = cv.GetSubRect( src_arr, (cx,0,cx,cy) )
    q3 = cv.GetSubRect( src_arr, (cx,cy,cx,cy) )
    q4 = cv.GetSubRect( src_arr, (0,cy,cx,cy) )
    d1 = cv.GetSubRect( src_arr, (0,0,cx,cy) )
    d2 = cv.GetSubRect( src_arr, (cx,0,cx,cy) )
    d3 = cv.GetSubRect( src_arr, (cx,cy,cx,cy) )
    d4 = cv.GetSubRect( src_arr, (0,cy,cx,cy) )

    if(src_arr is not dst_arr):
        if( not cv.CV_ARE_TYPES_EQ( q1, d1 )):
            cv.Error( cv.CV_StsUnmatchedFormats, "cv.ShiftDFT", "Source and Destination arrays must have the same format", __FILE__, __LINE__ )

        cv.Copy(q3, d1)
        cv.Copy(q4, d2)
        cv.Copy(q1, d3)
        cv.Copy(q2, d4)

    else:
        cv.Copy(q3, tmp)
        cv.Copy(q1, q3)
        cv.Copy(tmp, q1)
        cv.Copy(q4, tmp)
        cv.Copy(q2, q4)
        cv.Copy(tmp, q2) 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:41,代码来源:dft.py

示例9: update_mhi

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import GetSize [as 别名]
def update_mhi(img, dst, diff_threshold):
    global last
    global mhi
    global storage
    global mask
    global orient
    global segmask
    timestamp = time.clock() / CLOCKS_PER_SEC # get current time in seconds
    size = cv.GetSize(img) # get current frame size
    idx1 = last
    if not mhi or cv.GetSize(mhi) != size:
        for i in range(N):
            buf[i] = cv.CreateImage(size, cv.IPL_DEPTH_8U, 1)
            cv.Zero(buf[i])
        mhi = cv.CreateImage(size,cv. IPL_DEPTH_32F, 1)
        cv.Zero(mhi) # clear MHI at the beginning
        orient = cv.CreateImage(size,cv. IPL_DEPTH_32F, 1)
        segmask = cv.CreateImage(size,cv. IPL_DEPTH_32F, 1)
        mask = cv.CreateImage(size,cv. IPL_DEPTH_8U, 1)

    cv.CvtColor(img, buf[last], cv.CV_BGR2GRAY) # convert frame to grayscale
    idx2 = (last + 1) % N # index of (last - (N-1))th frame
    last = idx2
    silh = buf[idx2]
    cv.AbsDiff(buf[idx1], buf[idx2], silh) # get difference between frames
    cv.Threshold(silh, silh, diff_threshold, 1, cv.CV_THRESH_BINARY) # and threshold it
    cv.UpdateMotionHistory(silh, mhi, timestamp, MHI_DURATION) # update MHI
    cv.CvtScale(mhi, mask, 255./MHI_DURATION,
                (MHI_DURATION - timestamp)*255./MHI_DURATION)
    cv.Zero(dst)
    cv.Merge(mask, None, None, None, dst)
    cv.CalcMotionGradient(mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3)
    if not storage:
        storage = cv.CreateMemStorage(0)
    seq = cv.SegmentMotion(mhi, segmask, storage, timestamp, MAX_TIME_DELTA)
    for (area, value, comp_rect) in seq:
        if comp_rect[2] + comp_rect[3] > 100: # reject very small components
            color = cv.CV_RGB(255, 0,0)
            silh_roi = cv.GetSubRect(silh, comp_rect)
            mhi_roi = cv.GetSubRect(mhi, comp_rect)
            orient_roi = cv.GetSubRect(orient, comp_rect)
            mask_roi = cv.GetSubRect(mask, comp_rect)
            angle = 360 - cv.CalcGlobalOrientation(orient_roi, mask_roi, mhi_roi, timestamp, MHI_DURATION)

            count = cv.Norm(silh_roi, None, cv.CV_L1, None) # calculate number of points within silhouette ROI
            if count < (comp_rect[2] * comp_rect[3] * 0.05):
                continue

            magnitude = 30.
            center = ((comp_rect[0] + comp_rect[2] / 2), (comp_rect[1] + comp_rect[3] / 2))
            cv.Circle(dst, center, cv.Round(magnitude*1.2), color, 3, cv.CV_AA, 0)
            cv.Line(dst,
                    center,
                    (cv.Round(center[0] + magnitude * cos(angle * cv.CV_PI / 180)),
                     cv.Round(center[1] - magnitude * sin(angle * cv.CV_PI / 180))),
                    color,
                    3,
                    cv.CV_AA,
                    0) 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:61,代码来源:motempl.py

示例10: run

# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import GetSize [as 别名]
def run(self):
        hist = cv.CreateHist([180], cv.CV_HIST_ARRAY, [(0,180)], 1 )
        backproject_mode = False
        while True:
            frame = cv.QueryFrame( self.capture )

            # Convert to HSV and keep the hue
            hsv = cv.CreateImage(cv.GetSize(frame), 8, 3)
            cv.CvtColor(frame, hsv, cv.CV_BGR2HSV)
            self.hue = cv.CreateImage(cv.GetSize(frame), 8, 1)
            cv.Split(hsv, self.hue, None, None, None)

            # Compute back projection
            backproject = cv.CreateImage(cv.GetSize(frame), 8, 1)

            # Run the cam-shift
            cv.CalcArrBackProject( [self.hue], backproject, hist )
            if self.track_window and is_rect_nonzero(self.track_window):
                crit = ( cv.CV_TERMCRIT_EPS | cv.CV_TERMCRIT_ITER, 10, 1)
                (iters, (area, value, rect), track_box) = cv.CamShift(backproject, self.track_window, crit)
                self.track_window = rect

            # If mouse is pressed, highlight the current selected rectangle
            # and recompute the histogram

            if self.drag_start and is_rect_nonzero(self.selection):
                sub = cv.GetSubRect(frame, self.selection)
                save = cv.CloneMat(sub)
                cv.ConvertScale(frame, frame, 0.5)
                cv.Copy(save, sub)
                x,y,w,h = self.selection
                cv.Rectangle(frame, (x,y), (x+w,y+h), (255,255,255))

                sel = cv.GetSubRect(self.hue, self.selection )
                cv.CalcArrHist( [sel], hist, 0)
                (_, max_val, _, _) = cv.GetMinMaxHistValue( hist)
                if max_val != 0:
                    cv.ConvertScale(hist.bins, hist.bins, 255. / max_val)
            elif self.track_window and is_rect_nonzero(self.track_window):
                cv.EllipseBox( frame, track_box, cv.CV_RGB(255,0,0), 3, cv.CV_AA, 0 )

            if not backproject_mode:
                cv.ShowImage( "CamShiftDemo", frame )
            else:
                cv.ShowImage( "CamShiftDemo", backproject)
            cv.ShowImage( "Histogram", self.hue_histogram_as_image(hist))

            c = cv.WaitKey(7) % 0x100
            if c == 27:
                break
            elif c == ord("b"):
                backproject_mode = not backproject_mode 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:54,代码来源:camshift.py


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