我正在尝试使用Swift代码使一些像素变透明,方法是将抗锯齿设置为true并将路径像素删除而变成透明。 为了进一步处理,我使用C ++将UIimage发送到opencv,它可以将路径边缘转换为黑色像素。
我想删除由opencv生成的不需要的黑色像素。 如何删除这些黑色像素?
在opencv中,只需将图像转换为mat,然后从mat转换为UIImage,就会出现相同的问题。
Swift代码:
在opencv中,只需将图像转换为mat,然后从mat转换为UIImage,就会出现相同的问题。
Swift代码:
guard let imageSize=image.size else{
return
}
UIGraphicsBeginImageContextWithOptions(imageSize,false,1.0)
guard let context = UIGraphicsGetCurrentContext() else{
return
}
context.setShouldAntialias(true)
context.setAllowsAntialiasing(true)
context.setShouldSubpixelQuantizeFonts(true)
context.interpolationQuality = .high
imgCanvas.image?.draw(in: CGRect(x: 0, y:0, width: (imgCanvas.image?.size.width)!, height: (imgCanvas.image?.size.height)!))
bezeirPath = UIBezierPath()
bezeirPath.move(to: fromPoint)
bezeirPath.addLine(to: toPoint)
bezeirPath.lineWidth=(CGFloat(widthOfLine) * scaleX )/scrollView.zoomScale
bezeirPath.lineCapStyle = CGLineCap.round
bezeirPath.lineJoinStyle=CGLineJoin.round
bezeirPath.flatness=0.0
bezeirPath.miterLimit=0.0
bezeirPath.usesEvenOddFillRule=true
UIColor.white.setStroke()
bezeirPath.stroke(with: .clear, alpha:0)
bezeirPath.close()
bezeirPath.fill()
UIColor.clear.set()
context.addPath(bezeirPath.cgPath)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
OpenCV 代码:
Mat source;
UIImageToMat(originalImage,source,true);
return MatToUIImage(source);
我尝试了各种方法来解决这个问题,查看了不同的资料,但都没有解决。我已经试图解决这个问题三天了。所以如果有人有任何与此问题相关的线索,那将会很有帮助! [