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


Python cv2.cv方法代码示例

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


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

示例1: __init__

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

示例2: detect_shirt

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def detect_shirt(self):
        
        
        #self.dst=cv2.inRange(self.norm_rgb,np.array([self.lb,self.lg,self.lr],np.uint8),np.array([self.b,self.g,self.r],np.uint8))
        self.dst=cv2.inRange(self.norm_rgb,np.array([20,20,20],np.uint8),np.array([255,110,80],np.uint8))
        cv2.threshold(self.dst,0,255,cv2.THRESH_OTSU+cv2.THRESH_BINARY)
        fg=cv2.erode(self.dst,None,iterations=2)
        #cv2.imshow("fore",fg)  
        bg=cv2.dilate(self.dst,None,iterations=3)
        _,bg=cv2.threshold(bg, 1,128,1)
        #cv2.imshow("back",bg)
        
        mark=cv2.add(fg,bg)
        mark32=np.int32(mark)
        cv2.watershed(self.norm_rgb,mark32)
        self.m=cv2.convertScaleAbs(mark32)
        _,self.m=cv2.threshold(self.m,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
        #cv2.imshow("final_tshirt",self.m)
        
        cntr,h=cv2.findContours(self.m,cv2.cv.CV_RETR_EXTERNAL,cv2.cv.CV_CHAIN_APPROX_SIMPLE)
               
        return self.m,cntr 
开发者ID:akash0x53,项目名称:virtual-dressing-room,代码行数:24,代码来源:Tshirt.py

示例3: filterCornersLine

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def filterCornersLine(corners, rows, cols):
    [vx, vy, x, y] = cv2.fitLine(corners, cv.CV_DIST_HUBER, 0, 0.1, 0.1)
    lefty = int((-x * vy / vx) + y)
    righty = int(((cols - x) * vy / vx) + y)

    cornerdata = []
    tt = 0
    for i in corners:
        xl, yl = i.ravel()
        # check distance to fitted line, only draw corners within certain range
        distance = dist(0, lefty, cols - 1, righty, xl, yl)
        if distance > 40:  ## threshold important -> make accessible
            cornerdata.append(tt)

        tt += 1

    corners_final = np.delete(corners, [cornerdata], axis=0)  # delete corners to form new array

    return corners_final 
开发者ID:hanneshoettinger,项目名称:opencv-steel-darts,代码行数:21,代码来源:DartsRecognition.py

示例4: CountCoins

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def CountCoins(img, cimg):
    circles = []
    try:
        circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
                            param1=50,param2=30,minRadius=0,maxRadius=0)
    except:
        circles = cv2.HoughCircles(img, cv.CV_HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)

    if(circles is None):
        return

    circles = np.uint16(np.around(circles))
    for i in circles[0, :]:
        # draw the outer circle
        cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2)
        # draw the center of the circle
        cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3) 
开发者ID:reza-arjmandi,项目名称:rpi-course,代码行数:19,代码来源:Count_Coins.py

示例5: update

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def update(_=None):
    noise = cv2.getTrackbarPos('noise', 'fit line')
    n = cv2.getTrackbarPos('point n', 'fit line')
    r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0
    outn = int(n*r)

    p0, p1 = (90, 80), (w-90, h-80)
    img = np.zeros((h, w, 3), np.uint8)
    cv2.line(img, toint(p0), toint(p1), (0, 255, 0))

    if n > 0:
        line_points = sample_line(p0, p1, n-outn, noise)
        outliers = np.random.rand(outn, 2) * (w, h)
        points = np.vstack([line_points, outliers])
        for p in line_points:
            cv2.circle(img, toint(p), 2, (255, 255, 255), -1)
        for p in outliers:
            cv2.circle(img, toint(p), 2, (64, 64, 255), -1)
        func = getattr(cv2.cv, cur_func_name)
        vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01)
        cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255))

    draw_str(img, (20, 20), cur_func_name)
    cv2.imshow('fit line', img) 
开发者ID:fatcloud,项目名称:PyCV-time,代码行数:26,代码来源:fitline.py

示例6: SaveImage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def SaveImage(event):
    global display
    params = list()
    params.append(cv.CV_IMWRITE_PNG_COMPRESSION)
    params.append(8)
    filename = datetime.datetime.now().strftime('%y%m%d%H%M%S_%f') + ".png"
    cv2.imwrite(filename, display, params) 
开发者ID:arturaugusto,项目名称:display_ocr,代码行数:9,代码来源:OCR.py

示例7: cleanup

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def cleanup(self):
            print "Shutting down vision node."
            cv.DestroyAllWindows() 
开发者ID:OpenAgricultureFoundation,项目名称:openag_cv,代码行数:5,代码来源:avi2ros.py

示例8: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def main(args):    
    try:
        a2r = AVI2ROS()
    except KeyboardInterrupt:
        print "Shutting down avi2ros..."
        cv.DestroyAllWindows() 
开发者ID:OpenAgricultureFoundation,项目名称:openag_cv,代码行数:8,代码来源:avi2ros.py

示例9: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def main(args):
    try:
        cvBridge(args)
        rospy.spin()
    except KeyboardInterrupt:
        print "Shutting down vision node."
        cv.DestroyAllWindows() 
开发者ID:OpenAgricultureFoundation,项目名称:openag_cv,代码行数:9,代码来源:BlobDetector.py

示例10: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def main(args):
    try:
        CV(args)
        rospy.spin()
    except KeyboardInterrupt:
        print "Shutting down vision node."
        cv.DestroyAllWindows() 
开发者ID:OpenAgricultureFoundation,项目名称:openag_cv,代码行数:9,代码来源:ObjectMeasurer.py

示例11: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def __init__(self):
		cv.StartWindowThread()
		cv.NamedWindow('Capture Feedback') 
开发者ID:starstuffharvestingstarlight,项目名称:tcg-ocr-scanner,代码行数:5,代码来源:handlers.py

示例12: image_captured

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def image_captured(self, args):
		(img, rect) = args
		(x, y, w, h) = rect

		cv2.rectangle(numpy.asarray(img[:,:]), (x,y+1), (x+w,y+1+h), (0, 0, 0))
		cv2.rectangle(numpy.asarray(img[:,:]), (x,y), (x+w,y+h), (50, 50, 250))
		
		#cv.PutText(img, message, (0,y+1+2*h), font, (255, 255, 255))
		#cv.PutText(img, message, (0,y+2*h), font, (0, 0, 0))
		#cv.ShowImage('Capture Feedback', cv2.fromarray(img[:,:]))
		cv.ShowImage('Capture Feedback', img) 
开发者ID:starstuffharvestingstarlight,项目名称:tcg-ocr-scanner,代码行数:13,代码来源:handlers.py

示例13: image_to_string

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def image_to_string(self, img):
		with Timer('image_to_string_save', 2):
			cv.SaveImage('media/tmp.png', img)
		with Timer('image_to_string_proc', 2):
			subprocess.call(
				['tesseract', 'media/tmp.png', 'media/tmp', '-l', 'eng', '-psm', '7', 'tesseract.config'],
				stdout=self.DEV_NULL,
				stderr=subprocess.STDOUT
			)
		with Timer('image_to_string_cat', 2):
			txt = self.file_to_string('media/tmp.txt')
		return txt 
开发者ID:starstuffharvestingstarlight,项目名称:tcg-ocr-scanner,代码行数:14,代码来源:tcg_ocr_scanner.py

示例14: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def __init__(self, queue, webcam):
		super(WebcamImageProvider, self).__init__(queue)
		self.camera = cv.CreateCameraCapture(webcam)
		img = cv.QueryFrame(self.camera)
		if img is None:
			raise queue.Empty
		self.running = True 
开发者ID:starstuffharvestingstarlight,项目名称:tcg-ocr-scanner,代码行数:9,代码来源:tcg_ocr_scanner.py

示例15: run

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import cv [as 别名]
def run(self):
		while self.running:
			img = cv.QueryFrame(self.camera)
			self.image_queue.put(img)
			c = cv.WaitKey(30) 
开发者ID:starstuffharvestingstarlight,项目名称:tcg-ocr-scanner,代码行数:7,代码来源:tcg_ocr_scanner.py


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