android mat教程,OpenCV for Android - Access elements of Mat
问题
What is the standard way to access and modify individual elements of a Mat in OpenCV4Android? Also, what is the format of the data for BGR (which is the default, I think) and grayscale?
edit: Let's make this more specific. mat.get(row, col) returns a double array. What is in this array?
回答1:
What is the standard way to access and modify individual elements of a Mat in OpenCV4Android?
A Mat is the thing we call a "matrix" in Mathematics - a rectangular array of quantities set out by rows and columns. Those "quantities" represent pixels in the case of an image Mat, (e.g. every element of a matrix can be the color of each pixel in an image Mat). From this tutorial:
in the above image you can see that the mirror of the car is nothing
more than a matrix containing all the intensity values of the pixel
points.
So how would you go about iterating through a matrix? How about this:
for (int row=0; row
for (int col=0; col
//...do what you want..
//e.g. get the value of the 3rd element of 2nd row
//by mat.get(2,3);
}
}
What is the standard way to access and modify individual elements of a Mat in OpenCV4Android?
You get the value of an element of Mat by using its function get(x)(y), where x is the first coordinate (row number) and y is the second coordinate (column number) of the element. For example to get the 4th element of the 7th row of a BGR image Mat named bgrImageMat, use the get method of Mat to get an array of type double, which will have a size of 3, each array element representing each of the Blue, Green, and Red channels of the BGR image format.
double [] bgrColor = bgrImageMat.get();
Also, what is the format of the data for BGR (which is the default, I think) and grayscale? edit: Let's make this more specific. mat.get(row, col) returns a double array. What is in this array?
You can read about BGR color format and grayscale from the web. e.g. BGR and Grayscale.
In short, BGR color format has 3 channels: Blue, Green and Red. So the double array returned by mat.get(row, col), when mat is a BGR image, is an array of size 3, and each of its elements contains the values of each of the Blue, green and red channels respectively.
Likewise, Grayscale format is a 1 channel color format, so the double returned will have a size of 1.
回答2:
If you just want to access some pixels do it by using double[] get(int row, int col) and writing using put(int row, int col, double... data). If you are thinking in accessing the whole image or iterate the data of the image in a loop the best thing you should do is copy the Mat data into a Java primitive data type. When you're done with the data operations just copy the data back into a Mat structure.
Images use CV_8U, if you have a grayscale image it will use CV_8UC1 if you have a RGB image it will use a Mat of CV_8UC3 (3 channels of CV_8U). CV_8U is the equivalent of byte in java. :)
I can give you and example of a method I use in Java (Android platform) to binarize a grayscale image:
private Mat featuresVectorBinarization(Mat fv){
int size = (int) fv.total() * fv.channels();
double[] buff = new double[size];
fv.get(0, 0, buff);
for(int i = 0; i < size; i++)
{
buff[i] = (buff[i] >= 0) ? 1 : 0;
}
Mat bv = new Mat(fv.size(), CvType.CV_8U);
bv.put(0, 0, buff);
return bv;
}
Hope that helps.
回答3:
What I could understand from learning about OpenCV Mat object is that Mat is object that can represent any image of W x H pixels.
Now lets say you want to access center pixel of your image then
X = W/2
Y = H/2
Then you can access pixel data as follows
double[] data = matObject.get(x,y);
Now what does data represent and what is size of data array.That depends on image type.
if image is grayscale then data.length = 1 , since there is one channel only , and data[0] represents color value of that pixel ie. 0(black) - 255(white)
if image is color image then data.length = 4(rgba) , since there are four channels , and data[0-n] represent color value of that pixel
来源:https://stackoverflow.com/questions/12394364/opencv-for-android-access-elements-of-mat
android mat教程,OpenCV for Android - Access elements of Mat相关推荐
- opencv android安装教程,opencv for android安装教程.doc
opencv for android安装教程 前言: ? ?最近android开发异常火热,随着手机性能越来越高,图像处程序也越来越重要, 由于opencv for android 网上教程大多为英文 ...
- android 教程概要,Android精通教程-第一节Android入门简介
前言 大家好,我是 Vic,今天给大家带来Android精通教程-第一节Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cea ...
- android实例教程_改造Android示例教程
android实例教程 Welcome to Retrofit Android Example Tutorial. Today we'll use the Retrofit library devel ...
- android unity3d 教程,Unity3D For Android 发布教程
我自认为抵挡诱惑的能力还是很强大的,关键的时候还能把持住自己.今天逛了一下南京的丹凤街,终于受不住Android这美眉的诱惑.她虽脸蛋不怎么滴,但身材火热,且性感,廉价,低碳!长相平凡,却气质绝佳!虽 ...
- opencv android模版匹配,Opencv for android 模板匹配
因为有这方面的需要所以,对模板查找搜寻了相关资料,只是对于算法的东西很难看得动,特别是opencv涉及的很多的数学方法. 所以只为了实现这个功能,因为需求比较简单,在网上也搜寻到了相关代码,就直接拿来 ...
- android achart教程,AChartEngine And Android Studio
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have to create an application that makes exte ...
- vlc for android 使用教程,VLC for android 使用手记
将vlc-android 中org.videolan.vlc包下面的这几个class 添加: Aout.java BitmapCache.java EventManager.java LibVLC.j ...
- Android Studio 教程(1)----配置
Android Studio 教程 配置 [Android Studio的优势] 基于Gradle的构建支持 Android特定重构和快速修复 更加丰富的模板代码,让创建程序更简单 提示工具更好地对程 ...
- Android Volley教程
In this android volley tutorial, we'll be implementing the Volley library in our application. If you ...
- Android Studio教程– Hello World App
Welcome to the Android Studio Tutorial. This is the first article in the android tutorial series and ...
最新文章
- php foreach是什么,php中foreach的用法是什么
- Maven 让事情变得简单
- 突发!又一个程序员在东南亚出事了...
- 无预测 不零售 | SAP统一需求预测平台
- 积极开展网络营销的AI换脸软件短短几日经历了从爆红到下架
- COM First Teck.
- 一行代码制作你的专属动态二维码-Python实现
- 【并发那些事】可见性问题的万恶之源
- python创建新工程_个人博客二|创建项目
- CodeForces - 1348D Phoenix and Science(贪心)
- java excel 操作 poi_Java使用apache poi进行excel相关操作
- Wexflow:C#中的开源工作流引擎
- gatsby_如何在Gatsby.js中使用本地状态保持页面之间的状态
- 大数据_MapperReduce_从CSV文件中读取数据到Hbase_测试---Hbase工作笔记0022
- 我是一个尝试做自媒体的程序员
- 国外大神一张图学会python-没有接触过编程Python难学吗?
- python分词词典_基于python的分词算法的实现(3) – 建立字典 | 学步园
- Java基础50道经典练习题(22年新版)
- RANSAC介绍(Matlab版直线拟合+平面拟合)
- python 豆瓣高分电影爬虫
热门文章
- 前端js、jQuery实现日期格式化、字符串格式化
- Improving Opencv 3 : Mask operations on matrices
- 190404每日一句
- opencv继承配库
- Atitit 人工智能体系树培训列表应用较为广泛的技术.docx Atitit 人工智能体系培训列表 目录 1. 1.NLP自然语言处理文本处理	2 1.1. 语言理解 分词	2 1.2. 抽取
- Atitit 外出活动实名制条例sak令[2018]第920号 《外出活动实名制管理条例》 SAK安全部令 第920号 现发布《外出活动实名制管理条例》,自2018年9月1日起施行。
- Atitit.虚拟机与指令系统的设计
- Atitit.导出excel报表的设计与实现java .net php 总结
- Atitit.实现继承的原理and方法java javascript .net c# php ...
- paip.配置ef_unified_filter() failed ext_filter_module mod_ext_filter.so apache 错误解决