약간의 문제가 있습니다. 코드가있어 모든 픽셀을 읽고 픽셀의 RGB 색상을 사용합니다. 그러나 그 전에는 그림을 청크로 잘라서 메모리를 초과하지 않고 더 큰 이미지를 계산할 수도 있습니다.특정 픽셀의 x, y 위치 얻기
Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
try {
decoder_image = BitmapRegionDecoder.newInstance(filePath,
false);
} catch (IOException e) {
e.printStackTrace();
}
try {
boolean bool_pixel = true;
final int width = decoder_image.getWidth();
final int height = decoder_image.getHeight();
// Divide the bitmap into 1100x1100 sized chunks and process it.
// This makes sure that the app will not be "overloaded"
int wSteps = (int) Math.ceil(width/1100.0);
int hSteps = (int) Math.ceil(height/1100.0);
Rect rect = new Rect();
for (int h = 0; h < hSteps; h++) {
for (int w = 0; w < wSteps; w++) {
int w2 = Math.min(width, (w + 1) * 1100);
int h2 = Math.min(height, (h + 1) * 1100);
rect.set(w * 1100, h * 1100, w2, h2);
bitmap_image = decoder_image.decodeRegion(rect,
null);
try {
int bWidth = bitmap_image.getWidth();
int bHeight = bitmap_image.getHeight();
int[] pixels = new int[bWidth * bHeight];
bitmap_image.getPixels(pixels, 0, bWidth, 0, 0,
bWidth, bHeight);
for (int y = 0; y < bHeight; y++) {
for (int x = 0; x < bWidth; x++) {
int index = y * bWidth + x;
int R = (pixels[index] >> 16) & 0xff; //bitwise shifting
int G = (pixels[index] >> 8) & 0xff;
int B = pixels[index] & 0xff;
total++;
if (R == 255){
//Save x,y position
}
if ((G > (R+2)) && (G > (B+2))) {
counter++;
}
}
}
} finally {
bitmap_image.recycle();
}
}
}
} finally {
decoder_image.recycle();
}
이 마법처럼 작동합니다 다음은 코드입니다. 인터넷에서 정보를 얻을 수 있었고,이 코드를 다시 만들었습니다.
하지만 지금 내가 원하는 것은 "전체"빨간색 픽셀 (255)을 감지하면 해당 픽셀의 x, y 위치를 표시해야합니다.
나는 이것이 매우 쉽다고 생각했지만, 나는 이미지를 척으로 자르기 때문에 나는 매우 이상한 x, y 위치 (내가 생각하는 것)를 얻는다.
나는 왜 이것을 원하게되는지 설명 할 것이다 : 이미지에서 그것들은 2 개의 빨간 픽셀이고 그 2는 사각형으로 변형되어야하지만, 나는 좋은 x, y 위치를 얻지 못한다.
그래서 명확한 질문을 얻으려면 : 어떻게하면 빨간색 픽셀의 x, y 위치를 얻을 수 있습니까?
어쩌면 아주 쉽지만, 어쨌든 나는 딱 맞는 위치를 얻지 못하고 심지어 닫히지도 않습니다. 포토샵에서 이미지를 열어서 이것을 확인하고, 붉은 픽셀의 x, y가 무엇인지 살펴 봅니다. 그러나 내 앱은 매우 이상한 좌표를줍니다.
추가 정보가 필요하면 의견을 말하십시오.
감사 이미 Bigflow
그래서 픽셀 위치를 계산하는 알고리즘을 만들어야합니까? – Th0rndike
잭의 대답은 정확했습니다 – Bigflow