当前位置:   article > 正文

整理python-opencv常用方法和报错_opencv中dtype报错

opencv中dtype报错

error: (-215) dims <= 2 && step[0] > 0 in function locateROI

没有读取到文件,可能是路径、文件名、后缀错了

error: (-215) (mtype == CV_8U || mtype == CV_8S) && _mask.sameSize(*psrc1) in function cv::binary_op

参数类型错误或两个参数大小不一致,出现在cv2.bitwise_and()中,可以.dtype, .shape查看

  • 对RGB图像调用bitwise_not,只有当图像中只有0和255这两种像素值时才能得到正确的反向结果
def cvtColor(src, code, dst=None, dstCn=None):

图像类型转换,code=cv2.COLOR_GRAY2BGR灰度图扩充为三通道,RGB2GRAY转灰度图,。。。

  1. def dilate(src, kernel, dst=None, anchor=None, iterations=None, borderType=None, borderValue=None):
  2. kernel = np.ones((5, 5), np.uint8) # 定义kernel
  3. gt = cv2.dilate(gt, kernel, iterations=1)

膨胀,可以对二值图像扩充mask

img_erode = cv2.erode(img,None,iterations=5)

侵蚀操作,参考这篇博客

def inpaint(src, inpaintMask, inpaintRadius, flags, dst=None): 

填充成和mask周围相近的颜色,可以粗糙的去反光

def illuminationChange(src, mask, dst=None, alpha=None, beta=None): 

用一个mask去除反光,mask必须比反光部位大一些,参考,常用参数alpha=0.4, beta=0.2

  1. def threshold(src, thresh, maxval, type, dst=None):
  2. . @param src input array (multiple-channel, 8-bit or 32-bit floating point).
  3. . @param dst output array of the same size and type and the same number of channels as src.
  4. . @param thresh threshold value.
  5. . @param maxval maximum value to use with the #THRESH_BINARY and #THRESH_BINARY_INV thresholding
  6. . types.
  7. . @param type thresholding type (see #ThresholdTypes).
  8. . @return the computed threshold value if Otsu's or Triangle methods used.

获得图像中值高于或低于阈值部分的mask,低于设置type=cv2.THRESH_BINARY_INV

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/611133
推荐阅读
相关标签
  

闽ICP备14008679号