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


Python cv2.ADAPTIVE_THRESH_MEAN_C属性代码示例

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


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

示例1: getSignature

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def getSignature(img):
    imgSize = np.shape(img)

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

    # Adaptive Thresholding requires the blocksize to be odd and bigger than 1
    blockSize = 1 / 8 * imgSize[0] / 2 * 2 + 1
    if blockSize <= 1:
        blockSize = imgSize[0] / 2 * 2 + 1
    const = 10

    mask = cv2.adaptiveThreshold(gImg, maxValue = 255, adaptiveMethod = cv2.ADAPTIVE_THRESH_MEAN_C, thresholdType = cv2.THRESH_BINARY, blockSize = blockSize, C = const)
    rmask = cv2.bitwise_not(mask)

    return (cv2.bitwise_and(img, img, mask=rmask), rmask)

# First Prompt 
开发者ID:vzat,项目名称:signature_extractor,代码行数:19,代码来源:masterForgery.py

示例2: read_file

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

示例3: adaptiveThreshold

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

示例4: get_name

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def get_name(img):
        #    cv2.imshow("method3", img)
        #    cv2.waitKey()
        print('name')
        _, _, red = cv2.split(img) #split 会自动将UMat转换回Mat
        red = cv2.UMat(red)
        red = hist_equal(red)
        red = cv2.adaptiveThreshold(red, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 151, 50)
        #    red = cv2.medianBlur(red, 3)
        red = img_resize(red, 150)
        img = img_resize(img, 150)
        # showimg(red)
        # cv2.imwrite('name.png', red)
        #    img2 = Image.open('address.png')
        # img = Image.fromarray(cv2.UMat.get(red).astype('uint8'))
        #return get_result_vary_length(red, 'chi_sim', img, '-psm 7')
        return get_result_vary_length(red, 'chi_sim', img, '--psm 7')
        # return punc_filter(pytesseract.image_to_string(img, lang='chi_sim', config='-psm 13').replace(" ","")) 
开发者ID:Raymondhhh90,项目名称:idcardocr,代码行数:20,代码来源:idcardocr.py

示例5: gradient_and_binary

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def gradient_and_binary(img_blurred, image_name='1.jpg', save_path='./'):  # 将灰度图二值化,后面两个参数调试用
    """
    求取梯度,二值化
    :param img_blurred: 滤波后的图片
    :param image_name: 图片名,测试用
    :param save_path: 保存路径,测试用
    :return:  二值化后的图片
    """
    gradX = cv2.Sobel(img_blurred, ddepth=cv2.CV_32F, dx=1, dy=0)
    gradY = cv2.Sobel(img_blurred, ddepth=cv2.CV_32F, dx=0, dy=1)
    img_gradient = cv2.subtract(gradX, gradY)
    img_gradient = cv2.convertScaleAbs(img_gradient)  # sobel算子,计算梯度, 也可以用canny算子替代

    # 这里改进成自适应阈值,貌似没用
    img_thresh = cv2.adaptiveThreshold(img_gradient, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 3, -3)
    # cv2.imwrite(os.path.join(save_path, img_name + '_binary.jpg'), img_thresh)  # 二值化 阈值未调整好

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
    img_closed = cv2.morphologyEx(img_thresh, cv2.MORPH_CLOSE, kernel)
    img_closed = cv2.morphologyEx(img_closed, cv2.MORPH_OPEN, kernel)
    img_closed = cv2.erode(img_closed, None, iterations=9)
    img_closed = cv2.dilate(img_closed, None, iterations=9)  # 腐蚀膨胀
    # 这里调整了kernel大小(减小),腐蚀膨胀次数后(增大),出错的概率大幅减小

    return img_closed 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:27,代码来源:cut_part.py

示例6: update_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def update_image(image_id, category_id = 0, image_filenames=[], enable_vis=True, enable_marker_dump=False):
    try:
        global contours, hierarchy, img, gray, g_image_filenames
        if len(image_filenames) > 0:
            g_image_filenames=image_filenames
        img=cv.imread(g_image_filenames[image_id])
        # print(g_image_filenames[image_id])
        cv.setTrackbarPos('image', 'marker', image_id)

        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        gray[np.where(gray <= [3])] = [187]
        gray = cv.medianBlur(gray, 11)

        if enable_vis:
            cv.imshow('gray', gray)

        if CANNY_MODE:
            thrs1 = cv.getTrackbarPos('thrs1', 'marker')
            thrs2 = cv.getTrackbarPos('thrs2', 'marker')
            bin = cv.Canny(gray, thrs1, thrs2, apertureSize=5)
        else:
            bin = cv.adaptiveThreshold(
                gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY_INV, 31, 10)

        if enable_vis:
            cv.imshow('bin', bin)

        _, contours0, hierarchy = cv.findContours(
            bin.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
        contours = [cnt for cnt in contours0 if cv.contourArea(cnt) > 200]

        if enable_vis:
            cv.imshow('image', img)
        update_contour(category_id, image_id, enable_vis, enable_marker_dump)
    except Exception:
        import traceback
        traceback.print_exc()
        raise 
开发者ID:jing-vision,项目名称:lightnet,代码行数:40,代码来源:auto_marker.py

示例7: extract_img_markers

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def extract_img_markers(img, workspace_ratio=1.0):
    """
    Extract working area from an image thanks to 4 Niryo's markers
    :param img: OpenCV image which contain 4 Niryo's markers
    :param workspace_ratio: Ratio between the width and the height of the area represented by the markers
    :return: extracted and warped working area image
    """

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

    img_thresh = cv2.adaptiveThreshold(gray, maxValue=255, adaptiveMethod=cv2.ADAPTIVE_THRESH_MEAN_C,
                                       thresholdType=cv2.THRESH_BINARY, blockSize=15, C=25)

    list_good_candidates = find_markers_from_img_thresh(img_thresh)
    if not list_good_candidates or len(list_good_candidates) > 6:
        return None

    if len(list_good_candidates) == 4:
        list_good_candidates = sort_markers_detection(list_good_candidates)
    else:
        list_good_candidates = complicated_sort_markers(list_good_candidates, workspace_ratio=workspace_ratio)
        if list_good_candidates is None:
            return None

    im_cut = extract_sub_img(img, list_good_candidates, ratio_w_h=workspace_ratio)
    return im_cut 
开发者ID:NiryoRobotics,项目名称:niryo_one_ros,代码行数:28,代码来源:markers_detection.py

示例8: draw_markers

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def draw_markers(img, workspace_ratio=1.0):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    img_thresh = cv2.adaptiveThreshold(gray, maxValue=255, adaptiveMethod=cv2.ADAPTIVE_THRESH_MEAN_C,
                                       thresholdType=cv2.THRESH_BINARY, blockSize=15, C=32)

    list_good_candidates = find_markers_from_img_thresh(img_thresh)
    if not list_good_candidates:
        return False, img
    im_draw = img.copy()
    for marker in list_good_candidates:
        cx, cy = marker.get_center()
        radius = marker.get_radius()
        cv2.circle(im_draw, (cx, cy), radius, (0, 0, 255), 2)
    if len(list_good_candidates) > 6:
        return False, im_draw

    if len(list_good_candidates) == 4:
        list_good_candidates = sort_markers_detection(list_good_candidates)
    else:
        list_good_candidates = complicated_sort_markers(list_good_candidates, workspace_ratio=workspace_ratio)
        if list_good_candidates is None:
            return False, im_draw

    for i, marker in enumerate(list_good_candidates[:4]):
        cx, cy = marker.get_center()
        radius = marker.get_radius()
        cv2.circle(im_draw, (cx, cy), radius, (0, 200, 0), 2)
        cv2.putText(im_draw, "{}".format(i + 1),
                    (cx + 5, cy - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 0), 3)
        cv2.putText(im_draw, "{}".format(i + 1),
                    (cx + 5, cy - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 200, 0), 2)
    return True, im_draw 
开发者ID:NiryoRobotics,项目名称:niryo_one_ros,代码行数:35,代码来源:markers_detection.py

示例9: preprocess_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def preprocess_image(self):

        gray = self.image

        #Applying Gaussian Blur to smooth out the noise
        gray = cv2.GaussianBlur(gray, (11, 11), 0)
        try:
            os.remove("StagesImages/1.jpg")
        except:
            pass
        cv2.imwrite("StagesImages/1.jpg", gray)

        # Applying thresholding using adaptive Gaussian|Mean thresholding
        gray = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C | cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 5, 2)
        try:
            os.remove("StagesImages/2.jpg")
        except:
            pass
        cv2.imwrite("StagesImages/2.jpg", gray)

        #Inverting the image
        gray = cv2.bitwise_not(gray)
        try:
            os.remove("StagesImages/3.jpg")
        except:
            pass
        cv2.imwrite("StagesImages/3.jpg", gray)

        #Dilating the image to fill up the "cracks" in lines
        kernel = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]], np.uint8)
        gray = cv2.dilate(gray, kernel)
        self.image = gray
        try:
            os.remove("StagesImages/4.jpg")
        except:
            pass
        cv2.imwrite("StagesImages/4.jpg", gray) 
开发者ID:neeru1207,项目名称:AI_Sudoku,代码行数:39,代码来源:BoardExtractor.py

示例10: binarization

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def binarization(image, block_size=5, C=10):
        """
        convert input image to binary image
        cv2.adaptiveThreshold is used, for detailed information, refer to opencv docs
        :param image:
        :return:
        """
        if image.ndim == 3:
            image_grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        else:
            image_grayscale = image

        binary_image = cv2.adaptiveThreshold(image_grayscale, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                                             cv2.THRESH_BINARY, block_size, C)
        return binary_image 
开发者ID:becauseofAI,项目名称:lffd-pytorch,代码行数:17,代码来源:augmentor.py

示例11: thresholdify

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def thresholdify(self, img):
        img = cv2.adaptiveThreshold(img.astype(np.uint8), 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                                    cv2.THRESH_BINARY, 11, 3)
        return 255 - img 
开发者ID:prajwalkr,项目名称:SnapSudoku,代码行数:6,代码来源:helpers.py

示例12: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def main():
    const = 2
    block_size = 51
    imagePath = "../data/sudoku.png"

    image = cv2.imread(imagePath, 0)

    cv2.imshow("Orignal Image", image)

    mean_thresh = \
        cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, block_size, const)
    gaussian_thresh = \
        cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, block_size, const)

    images = [image, mean_thresh, gaussian_thresh]
    titles = ["Orignals", "Mean", "Gaussian"]

    cv2.imshow("Mean Image", mean_thresh)
    cv2.imshow("Gaussian Image", gaussian_thresh)

    for i in range(3):
        plt.subplot(3, 1, i + 1)
        plt.imshow(images[i], cmap='gray')
        plt.title(titles[i])

    plt.show()

    cv2.waitKey(0)
    cv2.destroyAllWindows() 
开发者ID:amarlearning,项目名称:Finger-Detection-and-Tracking,代码行数:31,代码来源:AdaptiveThresholding.py

示例13: mean

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def mean(gray_img, max_value, object_type="light"):
    """Creates a binary image from a grayscale image based on the mean adaptive threshold method.

    Inputs:
    gray_img     = Grayscale image data
    max_value    = value to apply above threshold (usually 255 = white)
    object_type  = "light" or "dark" (default: "light")
                   - If object is lighter than the background then standard thresholding is done
                   - If object is darker than the background then inverse thresholding is done

    Returns:
    bin_img      = Thresholded, binary image

    :param gray_img: numpy.ndarray
    :param max_value: int
    :param object_type: str
    :return bin_img: numpy.ndarray
    """
    # Set the threshold method
    threshold_method = ""
    if object_type.upper() == "LIGHT":
        threshold_method = cv2.THRESH_BINARY
    elif object_type.upper() == "DARK":
        threshold_method = cv2.THRESH_BINARY_INV
    else:
        fatal_error('Object type ' + str(object_type) + ' is not "light" or "dark"!')

    params.device += 1

    bin_img = _call_adaptive_threshold(gray_img, max_value, cv2.ADAPTIVE_THRESH_MEAN_C, threshold_method,
                                       "_mean_threshold_")

    return bin_img


# Otsu autothreshold 
开发者ID:danforthcenter,项目名称:plantcv,代码行数:38,代码来源:threshold_methods.py

示例14: processing

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def processing(self, img):
        super().processing(img)
        print("真正的核心算法:边缘提取算法")
        newImg = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 5, 10)
        return newImg 
开发者ID:luoweifu,项目名称:PyDesignPattern,代码行数:7,代码来源:ImageProcessing.py

示例15: remove_noise_and_smooth

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ADAPTIVE_THRESH_MEAN_C [as 别名]
def remove_noise_and_smooth(file_name):
    logging.info('Removing noise and smoothening image')
    img = cv2.imread(file_name, 0)
    filtered = cv2.adaptiveThreshold(img.astype(np.uint8), 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 41, 3)
    kernel = np.ones((1, 1), np.uint8)
    opening = cv2.morphologyEx(filtered, cv2.MORPH_OPEN, kernel)
    closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)
    img = image_smoothening(img)
    or_image = cv2.bitwise_or(img, closing)
    return or_image 
开发者ID:yardstick17,项目名称:image_text_reader,代码行数:12,代码来源:remove_noise.py


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