2012-11-11 99 views
0

的圖像我已經使用OPENCV for android在動態相機視圖中進行斑點檢測。我想爲設備的SD卡中存在的靜態位圖圖像執行類似的功能。我嘗試使用int android.graphics.Bitmap.getPixel(int x,int y),但它效率不高。處理需要很多時間。 所以,我想知道是否有可能使用openCV在位圖圖像中進行斑點檢測?用於處理位圖的OpenCV android

回答

2

您不應該直接在位圖上進行處理,因爲它會變慢。 最好將位圖轉換爲opencv Mat結構,處理Mat,然後將其轉換回位圖。

要使用opencv檢測斑點,可用的最佳工具是Imgproc.findContours如果搜索,您會發現很多關於findContours的內容。

要做到位圖轉換墊:

0

而不是使用Bitmap.getPixel(x,y),您應該真的考慮將所有像素都放入數組中並以這種方式進行處理。

Bitmap b=BitmapFactor.decodeFromFile(""); 
int[] pixels=new int[b.getWidth()*b.getHeight()]; 
bitmap.getPixels(pixels, 0, b.getWidth(), 0, 0, b.getWidth(), b.getHeight()); 
for(int x=0;x<w;x++){ 
    for(int y=0;y<h;y++){ 
     int pixel=pixels[y*b.getWidth()+x]; 
     // do something with that pixel 
    } 
} 
bitmap.setPixels(pixels, 0, b.getWidth(), 0, 0, b.getWidth(), b.getHeight());