Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The callback for receiving the raw H264 video data for camera live view
- mReceivedVideoDataListener = new VideoFeeder.VideoDataListener() {
- @Override
- public void onReceive(byte[] videoBuffer, int size) {
- //Log.d("BytesReceived", Integer.toString(videoStreamFrameNumber));
- if (videoStreamFrameNumber++%30 == 0){
- //convert video buffer to opencv array
- OpenCvAndModelAsync openCvAndModelAsync = new OpenCvAndModelAsync();
- openCvAndModelAsync.execute(videoBuffer);
- }
- if (mCodecManager != null) {
- mCodecManager.sendDataToDecoder(videoBuffer, size);
- }
- }
- };
- @Override
- public void onYuvDataReceived(final ByteBuffer yuvFrame, int dataSize, final int width, final int height) {
- //In this demo, we test the YUV data by saving it into JPG files.
- //DJILog.d(TAG, "onYuvDataReceived " + dataSize);
- if (count++ % 30 == 0 && yuvFrame != null) {
- final byte[] bytes = new byte[dataSize];
- yuvFrame.get(bytes);
- AsyncTask.execute(new Runnable() {
- @Override
- public void run() {
- if (bytes.length >= width * height) {
- Log.d("MatWidth", "Made it");
- YuvImage yuvImage = saveYuvDataToJPEG(bytes, width, height);
- Bitmap rgbYuvConvert = convertYuvImageToRgb(yuvImage, width, height);
- Mat yuvMat = new Mat(height, width, CvType.CV_8UC1);
- yuvMat.put(0, 0, bytes);
- //OpenCv Stuff
- }
- }
- });
- }
- }
- /* Async OpenCV Code */
- private class OpenCvAndModelAsync extends AsyncTask<byte[], Void, double[]> {
- @Override
- protected double[] doInBackground(byte[]... params) {//Background Code Executing. Don't touch any UI components
- //get fpv feed and convert bytes to mat array
- Mat videoBufMat = new Mat(4, params[0].length, CvType.CV_8UC4);
- videoBufMat.put(0,0, params[0]);
- //if I add this in it says the bytes are empty.
- //Mat videoBufMat = Imgcodecs.imdecode(encodeVideoBuf, Imgcodecs.IMREAD_ANYCOLOR);
- //encodeVideoBuf.release();
- Log.d("MatRgba", videoBufMat.toString());
- for (int i = 0; i< videoBufMat.rows(); i++){
- for (int j=0; j< videoBufMat.cols(); j++){
- double[] rgb = videoBufMat.get(i, j);
- Log.i("Matrix", "red: "+rgb[0]+" green: "+rgb[1]+" blue: "+rgb[2]+" alpha: "
- + rgb[3] + " Length: " + rgb.length + " Rows: "
- + videoBufMat.rows() + " Columns: " + videoBufMat.cols());
- }
- }
- double[] center = openCVThingy(videoBufMat);
- return center;
- }
- protected void onPostExecute(double[] center) {
- //handle ui or another async task if necessary
- }
- }
- 2019-05-23 21:14:29.601 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 2425
- 2019-05-23 21:14:29.802 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 2659
- 2019-05-23 21:14:30.004 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6
- 2019-05-23 21:14:30.263 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6015
- 2019-05-23 21:14:30.507 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6
- 2019-05-23 21:14:30.766 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 4682
- 2019-05-23 21:14:31.005 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6
- 2019-05-23 21:14:31.234 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 2840
- 2019-05-23 21:14:31.433 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 4482
- 2019-05-23 21:14:31.664 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6
- 2019-05-23 21:14:31.927 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 4768
- 2019-05-23 21:14:32.174 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6
- 2019-05-23 21:14:32.433 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 4700
- 2019-05-23 21:14:32.668 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6
- 2019-05-23 21:14:32.864 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 4740
- 2019-05-23 21:14:33.102 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 6
- 2019-05-23 21:14:33.365 21431-22086/com.dji.simulatorDemo D/VideoBufferSize: 4640
- Mat videoBufMat = Imgcodecs.imdecode(new MatOfByte(params[0]), Imgcodecs.IMREAD_UNCHANGED);
- Mat encodeVideoBuf = new Mat(4, params[0].length, CvType.CV_8UC4);
- encodeVideoBuf.put(0,0, params[0]);
- Mat videoBufMat = Imgcodecs.imdecode(encodeVideoBuf, Imgcodecs.IMREAD_UNCHANGED);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement