[問題] android onPreviewframe RGB value

看板AndroidDev作者 (地表男孩)時間10年前 (2014/07/14 15:59), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
大家好,小弟正在開發一款跟相機有關的app 目前遇到一些問題想請教一下各位前輩 我用onPreview產生格式為NV21的byte[]data轉換為RGB 公示如下: for(int y = 0; y < height; y++) { for(int x = startX; x < startX+width; x++) { Y = (0xff & ((int) data[(startY + y)*framewidth + x])); V = (0xff & ((int) data[framesize + ((startY + y) >> 1) * framewidth + (x & ~ 1) + 0])); U = (0xff & ((int) data[framesize + ((startY + y) >> 1) * framewidth + (x & ~ 1) + 1])); Y = Y < 16 ? 16 : Y; r = (int) (1.164f * (Y - 16) + 1.596f * (V - 128)); g = (int) (1.164f * (Y - 16) - 0.813f * (V - 128) - 0.391f * (U - 128)); b = (int) (1.164f * (Y - 16) + 2.018f * (U - 128)); r = r < 0 ? 0 : (r > 255 ? 255 : r); g = g < 0 ? 0 : (g > 255 ? 255 : g); b = b < 0 ? 0 : (b > 255 ? 255 : b); } } 同時我把每0.1秒的byte [] data轉成圖片存進手機 方法如下: if(imageFormat == ImageFormat.NV21) { Rect rect = new Rect(0, 0, param.getPreviewSize().width, param.getPreviewSize().height); YuvImage img = new YuvImage(picturerawdata, ImageFormat.NV21, param.getPreviewSize().width, param.getPreviewSize().height, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSS"); java.util.Date date = new java.util.Date(); String now = formatter.format(date); File file = new File(Environment.getExternalStorageDirectory().toString() + now + ".bmp"); try { img.compressToJpeg(rect, 100, baos); FileOutputStream fos = new FileOutputStream(file); fos.write(baos.toByteArray()); fos.flush(); fos.close(); } 值順利的取到的,圖片也順利的存到手機了 可是問題來了 當我用一些軟體如imageJ去分析我存的照片時 RGB數值與我直接用nv21的byte[] data轉成的RGB數值卻差了10~15左右 想請問其中的數值差異來自何處?這樣的差異是正常的嗎?還是是我哪邊出了問題? 先謝謝各位前輩的幫助了!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.16.198 ※ 文章網址: http://www.ptt.cc/bbs/AndroidDev/M.1405324790.A.374.html

07/15 09:36, , 1F
跟壓縮成Jpeg有關係吧?jpeg失真壓縮
07/15 09:36, 1F

07/16 20:57, , 2F
但是通常壓縮不是只會濾掉高頻的部分嗎?
07/16 20:57, 2F

07/16 20:58, , 3F
所以出來的值理論上應該不會差到15這麼多不是嗎~?
07/16 20:58, 3F
文章代碼(AID): #1JmutsDq (AndroidDev)