我使用opencv通過使用opencv將android位圖轉換爲grescale。以下是我正在使用的代碼,灰度Iplimage到android位圖
IplImage image = IplImage.create(bm.getWidth(), bm.getHeight(), IPL_DEPTH_8U, 4); //creates default image
bm.copyPixelsToBuffer(image.getByteBuffer());
int w=image.width();
int h=image.height();
IplImage grey=cvCreateImage(cvSize(w,h),image.depth(),1);
cvCvtColor(image,grey,CV_RGB2GRAY);
bm是源圖像。此代碼工作正常,並轉換爲灰度,我測試了它通過保存到SD卡,然後再次加載,但當我嘗試使用下面的方法加載它我的應用程序崩潰,任何建議。
bm.copyPixelsFromBuffer(grey.getByteBuffer());
iv1.setImageBitmap(bm);
iv1是imageview,我想設置bm。
這是正確的,但它太慢了...... 800x600 img需要5秒。更快的解決方案? –
對於性能嚴重的代碼,本機無法實現。這個可能有點老,但是會告訴你如何去做:http://www.ibm.com/developerworks/cn/education/opensource/os-androidndk/。 – bytefish