本文整理汇总了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()
示例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
示例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()
示例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
示例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()
示例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
示例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])
示例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
示例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
示例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
示例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)
# 一阶微分算子
#=======================================================================================================================
示例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