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


Python cv2.HOUGH_GRADIENT属性代码示例

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


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

示例1: findPiccircle

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def findPiccircle(frame, color):

	hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)	
	color_dict = color_list.getColorList()
	mask = cv2.inRange(hsv, color_dict[color][0], color_dict[color][1])
	dilated = cv2.dilate(mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)), iterations=2)
	## 需要修改minRadius以及maxRadius,用来限制识别圆的大小,排除其他的干扰
	circles = cv2.HoughCircles(dilated, cv2.HOUGH_GRADIENT, 1, 1000, param1=15, param2=10, minRadius=15, maxRadius=50)
	
	center = None
	if circles is not None:
		x, y, radius = circles[0][0]
		center = (x, y)
		cv2.circle(frame, center, radius, (0, 255, 0), 2)
		cv2.circle(frame, center, 2, (0,255,0), -1, 8, 0 );
		print('圆心:{}, {}'.format(x, y))
		
	cv2.imshow('result', frame)	
	
	if center != None:
		return center 
开发者ID:yzy1996,项目名称:Python-Code,代码行数:23,代码来源:detect_picture_color_circle.py

示例2: hough_circles

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def hough_circles(self):
        src = self.cv_read_img(self.src_file)
        if src is None:
            return

        dst = cv.pyrMeanShiftFiltering(src, 10, 100)
        cimage = cv.cvtColor(dst, cv.COLOR_BGR2GRAY)
        circles = cv.HoughCircles(cimage, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
        circles = np.uint16(np.around(circles))
        for i in circles[0, :]:
            cv.circle(src, (i[0], i[1]), i[2], (0, 0, 255), 2)
            cv.circle(src, (i[0], i[1]), 2, (255, 0, 255), 2)

        self.decode_and_show_dst(src)

    # 轮廓发现 
开发者ID:itisyang,项目名称:ImageMiniLab,代码行数:18,代码来源:ImageMiniLab.py

示例3: CountCoins

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

示例4: FindWand

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def FindWand():
    global rval,old_frame,old_gray,p0,mask,color,ig,img,frame
    try:
        rval, old_frame = cam.read()
	cv2.flip(old_frame,1,old_frame)
        old_gray = cv2.cvtColor(old_frame,cv2.COLOR_BGR2GRAY)
        equalizeHist(old_gray)
	old_gray = GaussianBlur(old_gray,(9,9),1.5)
        dilate_kernel = np.ones(dilation_params, np.uint8)
        old_gray = cv2.dilate(old_gray, dilate_kernel, iterations=1)
        clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8,8))
        old_gray = clahe.apply(old_gray)
        #TODO: trained image recognition
        p0 = cv2.HoughCircles(old_gray,cv2.HOUGH_GRADIENT,3,50,param1=240,param2=8,minRadius=4,maxRadius=15)
	if p0 is not None:
            p0.shape = (p0.shape[1], 1, p0.shape[2])
            p0 = p0[:,:,0:2] 
            mask = np.zeros_like(old_frame)
            ig = [[0] for x in range(20)]
        print "finding..."
        threading.Timer(3, FindWand).start()
    except:
        e = sys.exc_info()[1]
        print "Error: %s" % e 
        exit 
开发者ID:sean-obrien,项目名称:rpotter,代码行数:27,代码来源:rpotter.py

示例5: read_captured_circles

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def read_captured_circles(self):
        img = cv2.cvtColor(self.query, cv2.COLOR_BGR2GRAY)
        img = cv2.medianBlur(img, 7)
        cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

        circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 30,
                                   param1=50, param2=30, minRadius=20, maxRadius=50)
        if circles is None:
            return
        circles = np.uint16(np.around(circles))
        for i in circles[0, :]:
            if i[1] < 400:
                continue
            self.circlePoints.append((i[0], i[1]))
        if self._debug:
            self.draw_circles(circles, cimg) 
开发者ID:will7200,项目名称:Yugioh-bot,代码行数:18,代码来源:trainer_matches.py

示例6: capture_white_circles

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def capture_white_circles(self):
        self.prep_for_white_circles()
        img = cv2.cvtColor(self.white_query, cv2.COLOR_BGR2GRAY)
        img = cv2.medianBlur(img, 1)
        cimg = cv2.cvtColor(self.query, cv2.COLOR_BGR2RGB)
        circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, img.shape[0] / 15,
                                   param1=50, param2=22, minRadius=5, maxRadius=60)
        if circles is None:
            return
        circles = np.uint16(np.around(circles))
        new_circles = []
        for i in circles[0, :]:
            if self.in_box(i[0], i[1]) and not self.in_blacklist(i[0], i[1]):
                self.circlePoints.append((i[0], i[1]))
                new_circles.append(i)
        if self._debug:
            # self.draw_circles(circles, cimg)
            if len(new_circles) > 0:
                self.draw_circles(np.array([new_circles]), cimg) 
开发者ID:will7200,项目名称:Yugioh-bot,代码行数:21,代码来源:trainer_matches.py

示例7: detect_circles

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def detect_circles(self,gray,img):
        circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 100, param2=150, minRadius=160)
        circles = np.uint16(np.around(circles))  # 把circles包含的圆心和半径的值变成整数
        cir = img.copy()

        for i in circles[0, :]:
            cv2.circle(cir, (i[0], i[1]), i[2], (0, 255, 0), 2, cv2.LINE_AA)  # 画圆
            cv2.circle(cir, (i[0], i[1]), 2, (0, 255, 0), 2, cv2.LINE_AA)  # 画圆心
        cv2.imshow("circles", cir)
        return cir

    # 霍夫直线变换:检测指针 
开发者ID:CherryXuan,项目名称:Pointer-meter-identification-and-reading,代码行数:14,代码来源:MeterReader.py

示例8: detect_blob

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def detect_blob(self, img, filters):
        """
            "filters" must be something similar to:
            filters = {
                'R': (150, 255), # (min, max)
                'S': (150, 255),
            }

        """
        acc_mask = ones(img.shape[:2], dtype=uint8) * 255

        rgb = img.copy()
        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

        for c, (min, max) in filters.items():
            img = rgb if c in 'RGB' else hsv

            mask = img[:, :, self.channels[c]]
            mask[mask < min] = 0
            mask[mask > max] = 0

            acc_mask &= mask

        kernel = ones((5, 5), uint8)
        acc_mask = cv2.dilate(cv2.erode(acc_mask, kernel), kernel)

        circles = cv2.HoughCircles(acc_mask, cv2.HOUGH_GRADIENT, 3, img.shape[0] / 5.)
        return circles.reshape(-1, 3) if circles is not None else [] 
开发者ID:poppy-project,项目名称:pypot,代码行数:30,代码来源:blob.py

示例9: find_circular_wells

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def find_circular_wells(self):
        """Simply use Hough transform to find circles in MultiWell Plate rgb image.
        The parameters used are optimised for 24 or 48WP"""


        dwnscl_factor = self.img_shape[0]/self.blur_im.shape[0]

        # find circles
        # parameters in downscaled units
        circle_goodness = 70;
        highest_canny_thresh = 10;
        min_well_dist = self.blur_im.shape[1]/3;    # max 3 wells along short side. bank on FOV not taking in all the entirety of the well
        min_well_radius = self.blur_im.shape[1]//7; # if 48WP 3 wells on short side ==> radius <= side/6
        max_well_radius = self.blur_im.shape[1]//4; # if 24WP 2 wells on short side. COnsidering intrawells space, radius <= side/4
        # find circles
        _circles = cv2.HoughCircles(self.blur_im,
                                   cv2.HOUGH_GRADIENT,
                                   dp=1,
                                   minDist=min_well_dist,
                                   param1=highest_canny_thresh,
                                   param2=circle_goodness,
                                   minRadius=min_well_radius,
                                   maxRadius=max_well_radius)
        _circles = np.squeeze(_circles); # because why the hell is there an empty dimension at the beginning?

        # convert back to pixels
        _circles *= dwnscl_factor;

        # output back into class property
        self.wells['x'] = _circles[:,0].astype(int)
        self.wells['y'] = _circles[:,1].astype(int)
        self.wells['r'] = _circles[:,2].astype(int)
        return 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:35,代码来源:FOVMultiWellsSplitter.py

示例10: cropImage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def cropImage(self, screenshot, captureTime, captureLat, captureLng, src_path):
        p = None
        raidNo = 0
        processes = []
        
        hash = str(time.time())
        orgScreen = screenshot
        height, width, channel = screenshot.shape
        gray=cv2.cvtColor(screenshot,cv2.COLOR_BGR2GRAY)
        gray=cv2.GaussianBlur(gray, (7, 7), 2)

        minRadius = int(((width / 4.736)) / 2) 
        maxRadius = int(((width / 4.736)) / 2)
        log.debug('Searching for Raid Circles with Radius from %s to %s px' % (str(minRadius), str(maxRadius)))
        
        circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=50,param2=30, minRadius=minRadius, maxRadius=maxRadius)
        
        if circles is not None:
            circles = np.round(circles[0, :]).astype("int")
            for (x, y, r) in circles:
                log.debug('Found Circle with x:%s, y:%s, r:%s' % (str(x), str(y), str(r)))
                raidNo += 1
                raidCropFilepath = os.path.join(args.temp_path, str(hash) + "_raidcrop" + str(raidNo) +".jpg")
                new_crop = orgScreen[y-r-int((r*2*0.03)):y+r+int((r*2*0.75)), x-r-int((r*2*0.03)):x+r+int((r*2*0.3))]
                cv2.imwrite(raidCropFilepath, new_crop)
                if args.ocr_multitask:
                    p = multiprocessing.Process(target=RaidScan.process, name='OCR-crop-analysis-' + str(raidNo), args=(raidCropFilepath, hash, raidNo, captureTime, captureLat, captureLng, src_path, r))
                else:
                    p = Thread(target=RaidScan.process, name='OCR-processing', args=(raidCropFilepath, hash, raidNo, captureTime, captureLat, captureLng, src_path, r))
                processes.append(p)          
                p.daemon = True
                p.start() 
开发者ID:Grennith,项目名称:Map-A-Droid,代码行数:34,代码来源:fileObserver.py

示例11: cropImage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def cropImage(self, image, raidNo, radius):
        gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
        gray=cv2.GaussianBlur(gray, (7, 7), 2)
        output = image.copy()
        height, width, channel = output.shape
        output = output[0:height*2/3,0:width]
        image_cols, image_rows, _ = image.shape
        circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=50,param2=30, minRadius=radius, maxRadius=radius)
        if circles is not None:
            circles = np.round(circles[0, :]).astype("int")
            for (x, y, r) in circles:
                        log.debug('[Crop: ' + str(raidNo) + ' (' + str(self.uniqueHash) +') ] ' + 'cropImage: Detect crop coordinates x: ' + str(x) +' y: ' + str(y) +' with radius: ' + str(r))
                        new_crop = output[y-r:y+r, x-r:x+r]
                        return new_crop
        return False 
开发者ID:Grennith,项目名称:Map-A-Droid,代码行数:17,代码来源:segscanner.py

示例12: FindNewPoints

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def FindNewPoints():
    global old_frame,old_gray,p0,mask,color,ig,img,frame
    try:
        try:
            old_frame = cam.capture(stream, format='jpeg')
        except:
            print("resetting points")
        data = np.fromstring(stream.getvalue(), dtype=np.uint8)
        old_frame = cv2.imdecode(data, 1)
        cv2.flip(old_frame,1,old_frame)
        old_gray = cv2.cvtColor(old_frame,cv2.COLOR_BGR2GRAY)
        #cv2.equalizeHist(old_gray,old_gray)
	    #old_gray = cv2.GaussianBlur(old_gray,(9,9),1.5)
        #dilate_kernel = np.ones(dilation_params, np.uint8)
        #old_gray = cv2.dilate(old_gray, dilate_kernel, iterations=1)

        #TODO: trained image recognition
        p0 = cv2.HoughCircles(old_gray,cv2.HOUGH_GRADIENT,3,100,param1=100,param2=30,minRadius=4,maxRadius=15)
        p0.shape = (p0.shape[1], 1, p0.shape[2])
        p0 = p0[:,:,0:2]
        mask = np.zeros_like(old_frame)
        ig = [[0] for x in range(20)]
        print("finding...")
        TrackWand()
	    #This resets the scene every three seconds
        threading.Timer(3, FindNewPoints).start()
    except:
        e = sys.exc_info()[1]
        print("FindWand Error: %s" % e )
        End()
        exit 
开发者ID:sean-obrien,项目名称:rpotter,代码行数:33,代码来源:rpotter.py

示例13: _get_circles

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def _get_circles(image_segment, params):

    temp = cv2.HoughCircles(image_segment.segmented_image, cv2.HOUGH_GRADIENT, params.dp, params.minDist,
                            param1=params.param1, param2=params.param2,
                            minRadius=params.minRadius, maxRadius=params.maxRadius)
    if temp is None:
        return []

    circle_tuples = temp[0]
    if len(circle_tuples) > params.max_num:
        circle_tuples = circle_tuples[:params.max_num]

    circles = [instantiators['circle'](instantiators['point'](x, y), radius)
               for x, y, radius in circle_tuples]
    return circles 
开发者ID:uwnlp,项目名称:geosolver,代码行数:17,代码来源:parse_primitives.py

示例14: houghCircles

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def houghCircles(path, counter):
    img = cv2.imread(path, 0)
    # img = cv2.medianBlur(img, 5)

    x = cv2.Sobel(img, -1, 1, 0, ksize=3)
    y = cv2.Sobel(img, -1, 0, 1, ksize=3)
    absx = cv2.convertScaleAbs(x)
    absy = cv2.convertScaleAbs(y)
    img = cv2.addWeighted(absx, 0.5, absy, 0.5, 0)

    # ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
    # channels = cv2.split(ycrcb)
    # cv2.equalizeHist(channels[0], channels[0])  #输入通道、输出通道矩阵
    # cv2.merge(channels, ycrcb)  #合并结果通道
    # cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img)

    # img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

    # cv2.imshow("img2", img)
    # cv2.imshow("grayimg", grayimg)

    circles = cv2.HoughCircles(
        img,
        cv2.HOUGH_GRADIENT,
        1,
        50,
        param1=50,
        param2=10,
        minRadius=2,
        maxRadius=0)

    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), 1)
        # draw the center of the circle
        cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 2)
    # cv2.imshow("img" + str(counter), cimg)
    return (i[0] + 3, i[1] + 3)


#彩色直方图均衡化 
开发者ID:vipstone,项目名称:faceai,代码行数:46,代码来源:eye.py

示例15: find_blob

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HOUGH_GRADIENT [as 别名]
def find_blob() :
    radius = 0
    # Load input image
    _, bgr_image = img.read()

    orig_image = bgr_image

    bgr_image = cv2.medianBlur(bgr_image, 3)

    # Convert input image to HSV
    hsv_image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2HSV)

    # Threshold the HSV image, keep only the red pixels
    lower_red_hue_range = cv2.inRange(hsv_image, (0, 100, 100), (10, 255, 255))
    upper_red_hue_range = cv2.inRange(hsv_image, (160, 100, 100), (179, 255, 255))
    # Combine the above two images
    red_hue_image = cv2.addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0)

    red_hue_image = cv2.GaussianBlur(red_hue_image, (9, 9), 2, 2)

    # Use the Hough transform to detect circles in the combined threshold image
    circles = cv2.HoughCircles(red_hue_image, cv2.HOUGH_GRADIENT, 1, 120, 100, 20, 10, 0)
    circles = np.uint16(np.around(circles))
    # Loop over all detected circles and outline them on the original image
    all_r = np.array([])
    # print("circles: %s"%circles)
    if circles is not None:
        try:
            for i in circles[0,:]:
                # print("i: %s"%i)
                all_r = np.append(all_r, int(round(i[2])))
            closest_ball = all_r.argmax()
            center=(int(round(circles[0][closest_ball][0])), int(round(circles[0][closest_ball][1])))
            radius=int(round(circles[0][closest_ball][2]))
            if draw_circle_enable:
                cv2.circle(orig_image, center, radius, (0, 255, 0), 5)
        except IndexError:
            pass
            # print("circles: %s"%circles)

    # Show images
    if show_image_enable:
        cv2.namedWindow("Threshold lower image", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Threshold lower image", lower_red_hue_range)
        cv2.namedWindow("Threshold upper image", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Threshold upper image", upper_red_hue_range)
        cv2.namedWindow("Combined threshold images", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Combined threshold images", red_hue_image)
        cv2.namedWindow("Detected red circles on the input image", cv2.WINDOW_AUTOSIZE)
        cv2.imshow("Detected red circles on the input image", orig_image)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        return (0, 0), 0
    if radius > 3:
        return center, radius
    else:
        return (0, 0), 0 
开发者ID:sunfounder,项目名称:SunFounder_PiCar-V,代码行数:60,代码来源:ball_tracker.py


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