如何将bitmap的像素数据转换成opencv的mat对象?
首先从bitmap中或者像素数据:
String imgPath="/data/data/org.opencv.samples.tutorial2/cache/test_img.png";
bitmap = BitmapFactory.decodeFile(imgPath);
ByteBuffer allocate = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(allocate);
array = allocate.array();
然后将像素数据复制给mat对象:(格式rgba)
Mat outs=Mat::zeros(h,w, CV_8UC4);
int index=0;
for (int i = 0; i < outs.rows; ++i) {
for (int j = 0; j < outs.cols; ++j) {
outs.at<Vec4b>(i,j)[0]= (uchar)arr_[index];
outs.at<Vec4b>(i,j)[1]= (uchar)arr_[index+1];
outs.at<Vec4b>(i,j)[2]= (uchar)arr_[index+2];
outs.at<Vec4b>(i,j)[3]= (uchar)arr_[index+3];
index+=4;
}
}
本文地址:https://blog.csdn.net/mhhyoucom/article/details/107487847
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!
网友评论