本篇内容介绍了“怎么用Android的opencv实现多通道分离与合并”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
目录
多通道分离
API
public static void split(Mat m, List<Mat> mv)
参数一:m,待分离的多通道图像
参数二:mv,分离后的单通道图像
操作
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_channel_split_merge)
mBgr = Utils.loadResource(this, R.drawable.test)
val imgList = mutableListOf<Mat>()
Core.split(mBgr, imgList)
mChannelB = imgList[0]
mChannelG = imgList[1]
mChannelR = imgList[2]
}
通道合并
API
public static void merge(List<Mat> mv, Mat dst)
操作
private fun showBGZero() {
val zero = Mat.zeros(mBgr.rows(), mBgr.cols(), CvType.CV_8UC1)
val list = mutableListOf<Mat>()
list.add(zero)
list.add(zero)
list.add(mChannelR)
val result = Mat()
Core.merge(list, result)
showMat(result)
result.release()
}
private fun showBRZero() {
val zero = Mat.zeros(mBgr.rows(), mBgr.cols(), CvType.CV_8UC1)
val list = mutableListOf<Mat>()
list.add(zero)
list.add(mChannelG)
list.add(zero)
val result = Mat()
Core.merge(list, result)
showMat(result)
result.release()
}
private fun showGRZero() {
val zero = Mat.zeros(mBgr.rows(), mBgr.cols(), CvType.CV_8UC1)
val list = mutableListOf<Mat>()
list.add(mChannelB)
list.add(zero)
list.add(zero)
val result = Mat()
Core.merge(list, result)
showMat(result)
result.release()
}
private fun showSwitchBR() {
val zero = Mat.zeros(mBgr.rows(), mBgr.cols(), CvType.CV_8UC1)
val list = mutableListOf<Mat>()
list.add(mChannelR)
list.add(mChannelG)
list.add(mChannelB)
val result = Mat()
Core.merge(list, result)
showMat(result)
result.release()
}
结果
“怎么用Android的opencv实现多通道分离与合并”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注天达云网站,小编将为大家输出更多高质量的实用文章!