當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.CV_16S屬性代碼示例

本文整理匯總了Python中cv2.CV_16S屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.CV_16S屬性的具體用法?Python cv2.CV_16S怎麽用?Python cv2.CV_16S使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在cv2的用法示例。


在下文中一共展示了cv2.CV_16S屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: laplacian

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def laplacian(filepathname):
    v = cv2.imread(filepathname)
    s = cv2.cvtColor(v, cv2.COLOR_BGR2GRAY)
    s = cv2.Laplacian(s, cv2.CV_16S, ksize=3)
    s = cv2.convertScaleAbs(s)
    cv2.imshow('nier',s)
    return s

    # ret, binary = cv2.threshold(s,40,255,cv2.THRESH_BINARY)
    # contours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    # for c in contours:
    #     x,y,w,h = cv2.boundingRect(c)
    #     if w>5 and h>10:
    #         cv2.rectangle(v,(x,y),(x+w,y+h),(155,155,0),1)
    # cv2.imshow('nier2',v)

    # cv2.waitKey()
    # cv2.destroyAllWindows() 
開發者ID:cilame,項目名稱:vrequest,代碼行數:20,代碼來源:pycv2.py

示例2: sobelOperT

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def sobelOperT(self, img, blursize, morphW, morphH):
        '''
            No different with sobelOper ? 
        '''
        blur = cv2.GaussianBlur(img, (blursize, blursize), 0, 0, cv2.BORDER_DEFAULT)

        if len(blur.shape) == 3:
            gray = cv2.cvtColor(blur, cv2.COLOR_RGB2GRAY)
        else:
            gray = blur

        x = cv2.Sobel(gray, cv2.CV_16S, 1, 0, 3)
        absX = cv2.convertScaleAbs(x)
        grad = cv2.addWeighted(absX, 1, 0, 0, 0)

        _, threshold = cv2.threshold(grad, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)

        element = cv2.getStructuringElement(cv2.MORPH_RECT, (morphW, morphH))
        threshold = cv2.morphologyEx(threshold, cv2.MORPH_CLOSE, element)

        return threshold 
開發者ID:SunskyF,項目名稱:EasyPR-python,代碼行數:23,代碼來源:plate_locate.py

示例3: sobel

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def sobel(filepathname):
    v = cv2.imread(filepathname)
    s = cv2.cvtColor(v,cv2.COLOR_BGR2GRAY)
    x, y = cv2.Sobel(s,cv2.CV_16S,1,0), cv2.Sobel(s,cv2.CV_16S,0,1)
    s = cv2.convertScaleAbs(cv2.subtract(x,y))
    s = cv2.blur(s,(9,9))
    cv2.imshow('nier',s)
    return s

    # ret, binary = cv2.threshold(s,40,255,cv2.THRESH_BINARY)
    # contours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    # for c in contours:
    #     x,y,w,h = cv2.boundingRect(c)
    #     if w>5 and h>10:
    #         cv2.rectangle(v,(x,y),(x+w,y+h),(155,155,0),1)
    # cv2.imshow('nier2',v)

    # cv2.waitKey()
    # cv2.destroyAllWindows() 
開發者ID:cilame,項目名稱:vrequest,代碼行數:21,代碼來源:pycv2.py

示例4: draw_mask

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def draw_mask(img, mask, thickness=3, color=(255, 0, 0)):
    def _get_edge(mask, thickness=3):
        dtype = mask.dtype
        x=cv2.Sobel(np.float32(mask),cv2.CV_16S,1,0, ksize=thickness) 
        y=cv2.Sobel(np.float32(mask),cv2.CV_16S,0,1, ksize=thickness)
        absX=cv2.convertScaleAbs(x)
        absY=cv2.convertScaleAbs(y)  
        edge = cv2.addWeighted(absX,0.5,absY,0.5,0)
        return edge.astype(dtype)
    
    img = img.copy()
    canvas = np.zeros(img.shape, img.dtype) + color
    img[mask > 0] = img[mask > 0] * 0.8 + canvas[mask > 0] * 0.2
    edge = _get_edge(mask, thickness)
    img[edge > 0] = img[edge > 0] * 0.2 + canvas[edge > 0] * 0.8
    return img 
開發者ID:liruilong940607,項目名稱:OCHumanApi,代碼行數:18,代碼來源:vis.py

示例5: differentialDerivativeOpenCv

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def differentialDerivativeOpenCv():
    img = cv2.imread("E:\\TestImages\\person.jpg")

    # 轉換成單通道灰度圖
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    x = cv2.Sobel(img, cv2.CV_16S, 1, 0)
    y = cv2.Sobel(img, cv2.CV_16S, 0, 1)
    # 進行微分計算後,可能會出現負值,將每個像素加上最小負數的絕對值
    absX = cv2.convertScaleAbs(x)  # 轉回uint8
    absY = cv2.convertScaleAbs(y)
    # img = cv2.addWeighted(absX, 0.5, absY, 0.5, 0)

    cv2.imshow("First order differential X", absX)
    cv2.imshow("First order differential Y", absY)
    cv2.waitKey(0)
    cv2.destroyAllWindows() 
開發者ID:luoweifu,項目名稱:PyDesignPattern,代碼行數:19,代碼來源:ImageProcessing.py

示例6: sobelOper

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def sobelOper(self, img, blursize, morphW, morphH):
        blur = cv2.GaussianBlur(img, (blursize, blursize), 0, 0, cv2.BORDER_DEFAULT)

        if len(blur.shape) == 3:
            gray = cv2.cvtColor(blur, cv2.COLOR_RGB2GRAY)
        else:
            gray = blur

        x = cv2.Sobel(gray, cv2.CV_16S, 1, 0, ksize=3, scale=1, delta=0, borderType=cv2.BORDER_DEFAULT)
        absX = cv2.convertScaleAbs(x)
        grad = cv2.addWeighted(absX, 1, 0, 0, 0)

        _, threshold = cv2.threshold(grad, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)

        element = cv2.getStructuringElement(cv2.MORPH_RECT, (morphW, morphH))
        threshold = cv2.morphologyEx(threshold, cv2.MORPH_CLOSE, element)

        return threshold 
開發者ID:SunskyF,項目名稱:EasyPR-python,代碼行數:20,代碼來源:plate_locate.py

示例7: generateEnergyMap

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def generateEnergyMap(image, file_extension, file_name):
	image = cv2.cvtColor(image.astype(np.uint8), cv2.COLOR_BGR2GRAY)
	wI(image, ['gray', file_extension, file_name])
	dx = cv2.Sobel(image, cv2.CV_16S, 1, 0, ksize=3)
	abs_x = cv2.convertScaleAbs(dx)
	dy = cv2.Sobel(image, cv2.CV_16S, 0, 1, ksize=3)
	abs_y = cv2.convertScaleAbs(dy)
	output = cv2.addWeighted(abs_x, 0.5, abs_y, 0.5, 0)
	wI(output, ['energy', file_extension, file_name]) 
開發者ID:avidLearnerInProgress,項目名稱:pyCAIR,代碼行數:11,代碼來源:opencv_generators.py

示例8: laplacian

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def laplacian(self, value, modify=False) -> np.ndarray:
        if not value:
            return self.origin
        _laplacian = cv2.convertScaleAbs(cv2.Laplacian(self.origin, cv2.CV_16S, ksize=3))
        if modify:
            self.origin = _laplacian
        return _laplacian 
開發者ID:kerlomz,項目名稱:captcha_trainer,代碼行數:9,代碼來源:pretreatment.py

示例9: edgedetect

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def edgedetect(channel):
    sobelX = cv2.Sobel(channel, cv2.CV_16S, 1, 0)
    sobelY = cv2.Sobel(channel, cv2.CV_16S, 0, 1)
    sobel = np.hypot(sobelX, sobelY)
    sobel[sobel > 255] = 255  # Some values seem to go above 255. However RGB channels has to be within 0-255
    return sobel 
開發者ID:ankonzoid,項目名稱:artificio,代碼行數:8,代碼來源:img2edges.py

示例10: __sobel_image__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def __sobel_image__(self,image,horizontal):
        """
        apply the sobel operator to a given image on either the vertical or horizontal axis
        basically copied from
        http://stackoverflow.com/questions/10196198/how-to-remove-convexity-defects-in-a-sudoku-square
        :param horizontal:
        :return:
        """
        if horizontal:
            dy = cv2.Sobel(image,cv2.CV_16S,0,2)
            dy = cv2.convertScaleAbs(dy)
            cv2.normalize(dy,dy,0,255,cv2.NORM_MINMAX)
            ret,close = cv2.threshold(dy,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

            kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(10,2))
        else:
            dx = cv2.Sobel(image,cv2.CV_16S,2,0)
            dx = cv2.convertScaleAbs(dx)
            cv2.normalize(dx,dx,0,255,cv2.NORM_MINMAX)
            ret,close = cv2.threshold(dx,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

            kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(2,10))

        close = cv2.morphologyEx(close,cv2.MORPH_CLOSE,kernel)

        return close 
開發者ID:zooniverse,項目名稱:aggregation,代碼行數:28,代碼來源:active_weather.py

示例11: preProcessing

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def preProcessing(self, img):
        print("梯度化處理...")
        x = cv2.Sobel(img, cv2.CV_16S, 1, 0)
        y = cv2.Sobel(img, cv2.CV_16S, 0, 1)
        absX = cv2.convertScaleAbs(x)  # 轉回uint8
        absY = cv2.convertScaleAbs(y)
        return cv2.addWeighted(absX, 0.5, absY, 0.5, 0)



# 一階微分算子
#======================================================================================================================= 
開發者ID:luoweifu,項目名稱:PyDesignPattern,代碼行數:14,代碼來源:ImageProcessing.py

示例12: __extract_grids__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_16S [as 別名]
def __extract_grids__(img,horizontal):
    assert len(img.shape) == 2
    # height,width = img.shape
    grid_lines = []

    if horizontal:
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5,1))
        d_image = cv2.Sobel(img,cv2.CV_16S,0,2)

    else:
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(1,5))

        d_image = cv2.Sobel(img,cv2.CV_16S,2,0)

    d_image = cv2.convertScaleAbs(d_image)
    cv2.normalize(d_image,d_image,0,255,cv2.NORM_MINMAX)
    ret,close = cv2.threshold(d_image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

    # _,th1 = cv2.threshold(d_image,127,255,cv2.THRESH_BINARY)

    close = cv2.morphologyEx(close,cv2.MORPH_DILATE,kernel)

    _,contour, hier = cv2.findContours(close.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
    for cnt in contour:
        x,y,w,h = cv2.boundingRect(cnt)
        perimeter = cv2.arcLength(cnt,True)
        if min(h,w) > 1 and (perimeter > 500):



            s = cnt.shape
            f = np.reshape(cnt,(s[0],s[2]))

            if horizontal and (w/h > 5):
                grid_lines.append(f)
                template = np.zeros(img.shape,np.uint8)
                template.fill(255)
                cv2.drawContours(template, [cnt], 0, 0, -1)
                plt.imshow(template)
                plt.show()

            elif not horizontal and (h/w > 5):
                grid_lines.append(f)


    return grid_lines 
開發者ID:zooniverse,項目名稱:aggregation,代碼行數:48,代碼來源:paper_quad.py


注:本文中的cv2.CV_16S屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。