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


Python cv2.ADAPTIVE_THRESH_GAUSSIAN_C属性代码示例

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


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

示例1: pre_process_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def pre_process_image(img, skip_dilate=False):
	"""Uses a blurring function, adaptive thresholding and dilation to expose the main features of an image."""

	# Gaussian blur with a kernal size (height, width) of 9.
	# Note that kernal sizes must be positive and odd and the kernel must be square.
	proc = cv2.GaussianBlur(img.copy(), (9, 9), 0)

	# Adaptive threshold using 11 nearest neighbour pixels
	proc = cv2.adaptiveThreshold(proc, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)

	# Invert colours, so gridlines have non-zero pixel values.
	# Necessary to dilate the image, otherwise will look like erosion instead.
	proc = cv2.bitwise_not(proc, proc)

	if not skip_dilate:
		# Dilate the image to increase the size of the grid lines.
		kernel = np.array([[0., 1., 0.], [1., 1., 1.], [0., 1., 0.]],np.uint8)
		proc = cv2.dilate(proc, kernel)

	return proc 
开发者ID:aakashjhawar,项目名称:SolveSudoku,代码行数:22,代码来源:SudokuExtractor.py

示例2: processImageForNeuralNet

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def processImageForNeuralNet(arg1, image=False):
	""" 
	Receives as parameter arg1 the path of the image to be converted or the image already captured with
	cv2 (in that case, pass image=True as a parameter). The return of this function (x) should be passed as
	input to a Network object by network.feedforward(x)
	"""
	SIDE_SIZE = 10
	TOTAL_SIZE = 100
	img = arg1
	if(not image):
		img = cv2.imread(arg1,0)
	img = cv2.resize(img,(SIDE_SIZE,SIDE_SIZE))
	img = cv2.adaptiveThreshold(img,1,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
	
	img = np.reshape(img, (TOTAL_SIZE, 1))
	return np.array(img, dtype='f') 
开发者ID:dalmia,项目名称:WannaPark,代码行数:18,代码来源:main.py

示例3: normalize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def normalize(im):
    """Converts `im` to black and white.

    Applying a threshold to a grayscale image will make every pixel either
    fully black or fully white. Before doing so, a common technique is to
    get rid of noise (or super high frequency color change) by blurring the
    grayscale image with a Gaussian filter."""
    im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)

    # Filter the grayscale image with a 3x3 kernel
    blurred = cv2.GaussianBlur(im_gray, (3, 3), 0)

    # Applies a Gaussian adaptive thresholding. In practice, adaptive thresholding
    # seems to work better than appling a single, global threshold to the image.
    # This is particularly important if there could be shadows or non-uniform
    # lighting on the answer sheet. In those scenarios, using a global thresholding
    # technique might yield paricularly bad results.
    # The choice of the parameters blockSize = 77 and C = 10 is as much as an art
    # as a science and domain-dependand.
    # In practice, you might want to try different  values for your specific answer
    # sheet.
    return cv2.adaptiveThreshold(
        blurred, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 77, 10) 
开发者ID:rbaron,项目名称:omr,代码行数:25,代码来源:omr.py

示例4: clean_plate

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def clean_plate(self, plate):
        gray = cv2.cvtColor(plate, cv2.COLOR_BGR2GRAY)
        thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
        _, contours, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

        if contours:
            areas = [cv2.contourArea(c) for c in contours]
            max_index = np.argmax(areas) # index of the largest contour in the area array
            
            max_cnt = contours[max_index]
            max_cntArea = areas[max_index]
            x,y,w,h = cv2.boundingRect(max_cnt)
            rect = cv2.minAreaRect(max_cnt)
            rotatedPlate = self.crop_rotated_contour(plate, rect)
            if not self.ratioCheck(max_cntArea, rotatedPlate.shape[1], rotatedPlate.shape[0]):
                return plate, False, None
            return rotatedPlate, True, [x, y, w, h]
        else:
            return plate, False, None 
开发者ID:longphungtuan94,项目名称:ALPR_System,代码行数:21,代码来源:class_PlateDetection.py

示例5: read_file

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def read_file(fname):
    image = cv2.imread(fname,0)


    image = cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2)
    # cv2.namedWindow('image', cv2.WINDOW_NORMAL)
    # cv2.imshow('image',image)
    # cv2.waitKey(0)
    # cv2.destroyAllWindows()

    # image = cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
    # cv2.imwrite("/home/ggdhines/temp.jpg",image)
    # assert False


    # _,image = cv2.threshold(image,200,255,cv2.THRESH_BINARY)

    # image = 255 - image
    # image = image > 0
    image = image.astype(np.float)

    return image 
开发者ID:zooniverse,项目名称:aggregation,代码行数:24,代码来源:temp.py

示例6: adaptiveThreshold

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def adaptiveThreshold(plates):
    for i, plate in enumerate(plates):
        img = cv2.imread(plate)

        gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
        cv2.imshow('gray', gray)

        ret, thresh = cv2.threshold(gray, 50, 255, cv2.THRESH_BINARY)
        # cv2.imshow('thresh', thresh)

        threshMean = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 10)
        # cv2.imshow('threshMean', threshMean)

        threshGauss = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 51, 27)
        cv2.imshow('threshGauss', threshGauss)
        cv2.imwrite("processed\\plate{}.png".format(i), threshGauss)

        cv2.waitKey(0) 
开发者ID:Link009,项目名称:LicensePlates-OCR,代码行数:20,代码来源:platesOCR.py

示例7: locate_text_area

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def locate_text_area(pdf_image_row_block):
    """
    locate the text area of the image row block
    :param pdf_image_row_block: color pdf image block
    :return:
    """
    gray_image = cv2.cvtColor(pdf_image_row_block, cv2.COLOR_BGR2GRAY)
    binarized_image = cv2.adaptiveThreshold(
        src=gray_image,
        maxValue=255,
        adaptiveMethod=cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
        thresholdType=cv2.THRESH_BINARY,
        blockSize=11,
        C=2
    )

    # sum along the col axis
    col_sum = np.sum(binarized_image, axis=0)
    idx_col_sum = np.argwhere(col_sum < col_sum.max())[:, 0]

    start_col = idx_col_sum[0] if idx_col_sum[0] > 0 else 0
    end_col = idx_col_sum[-1]
    end_col = end_col if end_col < pdf_image_row_block.shape[1] else pdf_image_row_block.shape[1] - 1

    return pdf_image_row_block[:, start_col:end_col, :] 
开发者ID:MaybeShewill-CV,项目名称:CRNN_Tensorflow,代码行数:27,代码来源:recongnize_chinese_pdf.py

示例8: cartoonise

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def cartoonise(self, img_rgb, num_down, num_bilateral, medianBlur, D, sigmaColor, sigmaSpace):
        # 用高斯金字塔降低取样
        img_color = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
        for _ in range(num_down):
            img_color = cv2.pyrDown(img_color)
        # 重复使用小的双边滤波代替一个大的滤波
        for _ in range(num_bilateral):
            img_color = cv2.bilateralFilter(img_color, d=D, sigmaColor=sigmaColor, sigmaSpace=sigmaSpace)
        # 升采样图片到原始大小
        for _ in range(num_down):
            img_color = cv2.pyrUp(img_color)
        if not self.Save_Edge:
            img_cartoon = img_color
        else:
            img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
            img_blur = cv2.medianBlur(img_gray, medianBlur)
            img_edge = cv2.adaptiveThreshold(img_blur, 255,
                                             cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                             cv2.THRESH_BINARY,
                                             blockSize=self.Adaptive_Threshold_Block_Size,
                                             C=self.C)
            img_edge = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2RGB)
            img_edge = cv2.resize(img_edge, img_color.shape[:2][::-1])
            img_cartoon = cv2.bitwise_and(img_color, img_edge)
        return cv2.cvtColor(img_cartoon, cv2.COLOR_RGB2BGR) 
开发者ID:MashiMaroLjc,项目名称:rabbitVE,代码行数:27,代码来源:Cartoonlization.py

示例9: processFile

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def processFile(self, img, debug=False):
        """
        Converts input image to grayscale & applies adaptive thresholding.
        """
        img = cv2.GaussianBlur(img,(5,5),0)
        # Convert to HSV
        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
        # Convert to grayscale
        gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
        # HSV Thresholding
        res,hsvThresh = cv2.threshold(hsv[:,:,0], 25, 250, cv2.THRESH_BINARY_INV)
        # Show adaptively thresholded image
        adaptiveThresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 115, 1)
        # Show both thresholded images
        # cv2.imshow("HSV Thresholded",hsvThresh)

        if debug:
            cv2.imshow("Adaptive Thresholding", adaptiveThresh)

        return img, adaptiveThresh 
开发者ID:nebbles,项目名称:DE3-ROB1-CHESS,代码行数:22,代码来源:mainDetect.py

示例10: _get_image_segments

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def _get_image_segments(image, kernel, block_size, c):
    binarized_image = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                            cv2.THRESH_BINARY_INV, block_size, c)

    labeled, nr_objects = ndimage.label(binarized_image, structure=kernel)
    slices = ndimage.find_objects(labeled)

    image_segments = {}
    for idx, slice_ in enumerate(slices):
        offset = instantiators['point'](slice_[1].start, slice_[0].start)
        sliced_image = image[slice_]
        boolean_array = labeled[slice_] == (idx+1)
        segmented_image = 255- (255-sliced_image) * boolean_array
        pixels = set(instantiators['point'](x, y) for x, y in np.transpose(np.nonzero(np.transpose(boolean_array))))
        binarized_segmented_image = cv2.adaptiveThreshold(segmented_image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                                          cv2.THRESH_BINARY_INV, block_size, c)

        image_segment = ImageSegment(segmented_image, sliced_image, binarized_segmented_image, pixels, offset, idx)
        image_segments[idx] = image_segment

    return image_segments 
开发者ID:uwnlp,项目名称:geosolver,代码行数:23,代码来源:parse_image_segments.py

示例11: PrepareImage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def PrepareImage(image):
  """Converts color image to black and white"""
  # work on gray scale
  bw = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)

  # remove noise, preserve edges
  bw = cv2.bilateralFilter(bw, 9, 75, 75)

  # binary threshold
  bw = cv2.adaptiveThreshold(bw, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                             cv2.THRESH_BINARY, 11, 2)
  return bw 
开发者ID:cfircohen,项目名称:airport,代码行数:14,代码来源:solver.py

示例12: turn_binary

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def turn_binary(old: np.ndarray) -> np.ndarray:
    grey = turn_grey(old).astype("uint8")
    return cv2.adaptiveThreshold(
        grey, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2
    ) 
开发者ID:williamfzc,项目名称:stagesepx,代码行数:7,代码来源:toolbox.py

示例13: find_items

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def find_items(maze_image):
    # Preprocessing to find the contour of the shapes
    h, w = maze_image.shape[0], maze_image.shape[1]
    dim = (h+w)//2
    b_and_w = cv2.cvtColor(maze_image, cv2.COLOR_BGR2GRAY)
    edges = cv2.GaussianBlur(b_and_w, (11, 11), 0)
    edges = cv2.adaptiveThreshold(edges, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 9, 2)

    cv2.rectangle(edges,(0, 0),(w-1,h-1),(255,255,255),16)
    contours, _ = cv2.findContours(edges, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

    # cv2.imshow('d', edges)

    items = []

    if contours:
        item_mask = np.zeros(edges.shape, np.uint8)
        conts = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=False)

        for cnt in conts:

            if cv2.contourArea(cnt) > 0.35*dim:
                return items, item_mask

            elif cv2.contourArea(cnt) > 0.05*dim:
                d = np.mean(cnt, axis=0)
                d[0][0], d[0][1] = int(round(d[0][0])), int(round(d[0][1]))

                # TODO adjust the size here?
                if cv2.contourArea(cnt) < 0.1*dim:
                    items.append((d, 'smol'))
                    cv2.drawContours(item_mask, [cnt], -1, (255,255,255), -1)
                else:
                    items.append((d, 'big'))
                    cv2.drawContours(item_mask, [cnt], -1, (255,255,255), -1)

    return items, item_mask 
开发者ID:guille0,项目名称:hazymaze,代码行数:39,代码来源:extract_lines.py

示例14: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("-d", "--image_train",
            help = "path for the images that you're going to invert")
    args = vars(ap.parse_args())
    if args.get("image", True):
        imgTrainingNumbers = cv2.imread(args["image_train"]) # read in training numbers image
        if imgTrainingNumbers is None:
            print "error: image not read from file \n\n"        # print error message to std out
            os.system("pause")                                  # pause so user can see error message
            return
    else:
        print("Please add -d or --image_train argument")

    imgGray = cv2.cvtColor(imgTrainingNumbers, cv2.COLOR_BGR2GRAY)          # get grayscale image
    imgBlurred = cv2.GaussianBlur(imgGray, (5,5), 0)                        # blur

                                                        # filter image from grayscale to black and white
    imgThresh = cv2.adaptiveThreshold(imgBlurred,                           # input image
                                      0,                                  # make pixels that pass the threshold full white
                                      cv2.ADAPTIVE_THRESH_GAUSSIAN_C,       # use gaussian rather than mean, seems to give better results
                                      cv2.THRESH_BINARY_INV,                # invert so foreground will be white, background will be black
                                      11,                                   # size of a pixel neighborhood used to calculate threshold value
                                      2)                                    # constant subtracted from the mean or weighted mean

    imgTrainingNumbers = np.invert(imgTrainingNumbers)
    cv2.imwrite("invert_"+args["image_train"],imgTrainingNumbers)
    cv2.imwrite("imgThresh_"+args["image_train"],imgThresh)
    return

################################################################################################### 
开发者ID:muchlisinadi,项目名称:ALPR-Indonesia,代码行数:33,代码来源:invert_imageData.py

示例15: preprocess

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_GAUSSIAN_C [as 别名]
def preprocess(imgOriginal):
    #coba = cv2.cvtColor(imgOriginal, cv2.COLOR_BGR2HSV)
    #cv2.imshow("hsv", coba )
    imgGrayscale = extractValue(imgOriginal)
    #cv2.imshow("imgGrayscale", imgGrayscale )

    imgGrayscale = np.invert(imgGrayscale) # last best use this
    #cv2.imshow("invert", imgGrayscale )
    imgMaxContrastGrayscale = maximizeContrast(imgGrayscale)
    #cv2.imshow("imgMaxContrastGrayscale", imgMaxContrastGrayscale )
    #imgMaxContrastGrayscale = np.invert(imgMaxContrastGrayscale)
    height, width = imgGrayscale.shape

    imgBlurred = np.zeros((height, width, 1), np.uint8)
    #cv2.imshow("c_3", imgBlurred )

    imgBlurred = cv2.GaussianBlur(imgMaxContrastGrayscale, GAUSSIAN_SMOOTH_FILTER_SIZE, 0)
    #cv2.imshow("imgBlurred", imgBlurred )
    #imgBlurred = np.invert(imgBlurred)
    imgThresh = cv2.adaptiveThreshold(imgBlurred, THRESHOLD_VALUE , cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, ADAPTIVE_THRESH_BLOCK_SIZE, ADAPTIVE_THRESH_WEIGHT)
    #imgThresh = np.invert(imgThresh)
    #cv2.imshow("cobaaa", imgThresh)

    return imgGrayscale, imgThresh
# end function

################################################################################################### 
开发者ID:muchlisinadi,项目名称:ALPR-Indonesia,代码行数:29,代码来源:Preprocess.py


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