0
我有一臺攝像機將原始RGB數據傳輸到雲端。 我正在拾取數據並在Spark中處理它(使用scala和OpenCV Java)。 我在正確加載RGB時遇到問題。這是原始圖像:RGB Image無法從ByteArray正確加載:opencv java(用scala包裝)
而這就是我得到相反:
我使用這個代碼是:
//mainCam is a byte array: val mainCam: Array[Byte]
val mainCam_mat = new Mat (360, 480, CvType.CV_8UC3)
mainCam_mat.put(0,0,mainCam)
//Destination is the path and file name e.g. /tmp/test/123.jpeg
Highgui.imwrite(destination, mainCam_mat)
基礎的在下面的輸入我試圖強制小endiann和使用intbuffers這種方式:
//mainCam is a byte array: val mainCam: Array[Byte]
val bb = IntBuffer.allocate(mainCam.length/4)
bb.put(ByteBuffer.wrap(mainCam).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer())
mainCam_raw.put(0,0,bb.array.map(_.toByte))
//Destination is the path and file name e.g. /tmp/test/123.jpeg
Highgui.imwrite(destination, mainCam_mat)
結果是這樣的:
感謝萊昂納多用於表明數據是未來作爲4通道RGBA。代碼更新爲:
//mainCam is a byte array: val mainCam: Array[Byte]
val mainCam_mat = new Mat (360, 480, CvType.CV_8UC4)
mainCam_mat.put(0,0,mainCam)
//Destination is the path and file name e.g. /tmp/test/123.jpeg
Highgui.imwrite(destination, mainCam_mat)
結果如下:
還有在圖像上的一些顆粒相比於第一可視化。對此有何想法?
請訪問[求助]也讀作[問]。你沒有包含足夠的細節來幫助你。我會檢查以確保你的java代碼不會以某種方式將字節「解碼」爲字符,這會破壞事物,並且確保字節順序是正確的(小端與大端)。除此之外,我們必須看到更多的代碼。 –
您的原始流式圖像是360 * 480嗎?看起來原始圖像更大。 –
@ Suhyeon Lee。是的,原始圖像是360 * 480。我張貼的圖片是欺騙性的,因爲我在發送數據的遠程機器上做了一個屏幕截圖。 與此同時,我已經嘗試了@ Jim Garrison在小尾數上提出的建議: val bb = IntBuffer.allocate(mainCam.length/4)bb.put(ByteBuffer.wrap(mainCam).order(ByteOrder。 LITTLE_ENDIAN).asIntBuffer()) mainCam_raw.put(0,0,bb.array.map(_。toByte)) 結果更好但不完美。我會發布它 – Ignacio