在android中检测图像的所有颜色
我必须在Android中提取所有颜色的图像,而不使用ML(谷歌视觉,IBM视觉识别) 我有下面的选择 1. 调色板库尝试提取以下六种颜色配置文件 2。获取特定像素的颜色在android中检测图像的所有颜色,android,image,image-processing,Android,Image,Image Processing,我必须在Android中提取所有颜色的图像,而不使用ML(谷歌视觉,IBM视觉识别) 我有下面的选择 1. 调色板库尝试提取以下六种颜色配置文件 2。获取特定像素的颜色 public static int getDominantColor(Bitmap bitmap) { Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, 1, 1, true); final int color = newBitmap.getPixel(0, 0); new
public static int getDominantColor(Bitmap bitmap) {
Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, 1, 1, true);
final int color = newBitmap.getPixel(0, 0);
newBitmap.recycle();
return color;
}
若我把位图分解成小尺寸,那个么找出颜色并保存在列表中。
然后是耗时和OutOfMemoryError
请建议任何图书馆查找图像的颜色
编辑
挑刺
InputStream stream = getContentResolver().openInputStream(
data.getData());
bitmap = BitmapFactory.decodeStream(stream);
stream.close()
从像素获取颜色代码
HashMap<Integer,Integer> colorList=new HashMap<>();
private void getAllColorInImages(Bitmap bitmap)
{
colorList.clear();
if(bitmap==null)
return;
int width=bitmap.getWidth();
int height=bitmap.getHeight();
for(int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
final int color = bitmap.getPixel(i, j);
colorList.put(color,color);
}
}
System.out.println("color list size "+colorList.size());
System.out.println("color list Name "+colorList);
}
HashMap colorList=newhashmap();
私有void getAllColorInImages(位图)
{
colorList.clear();
如果(位图==null)
返回;
int width=bitmap.getWidth();
int height=bitmap.getHeight();
对于(int i=0;我是否需要位图中使用的每种颜色或图像的一种平均颜色?每种颜色。它用于分析目的。如果我在图像中搜索一种特定颜色,而该颜色在图像的一小部分中,那么在平均情况下,我们将丢失该颜色。同样,您试图实现的确切目标是什么?例如,在ima中查找像素数有些事情需要使用本机代码来完成,您的需求属于这一类,如果您关心性能和效率,请尝试使用OpenCV。请参阅此@AseemSharma答案与OpenCV无关,类似于查找colar和每个像素并保存在列表中。