Ask Your Question

iuq's profile - activity

2019-07-05 00:37:25 -0600 received badge  Famous Question (source)
2018-05-24 02:37:07 -0600 received badge  Notable Question (source)
2017-11-21 05:02:23 -0600 received badge  Popular Question (source)
2017-03-28 06:34:00 -0600 asked a question Why am I getting empty stitched image?

Hi,

I have two webcams connected to my android tablet - I am capturing the frames and stitching them and display. My java code -

    Log.i(TAG, "Processing .......");

    Mat left = null, right = null;

    //HEIGHT = 640 and WIDTH=480
    left = new Mat(HEIGHT + HEIGHT / 2, WIDTH, CvType.CV_8UC1);
    right = new Mat(HEIGHT + HEIGHT / 2, WIDTH, CvType.CV_8UC1);

    //list of images to be stitiched
    ArrayList<Mat> mats = new ArrayList<>(2);
    mats.add(left);
    mats.add(right);

    // for testing purpose only - if captured frames are proper. 
    // I am able to capture the frames and save them as PNG. It displays fine.
    Bitmap bmpL = Bitmap.createBitmap(left.cols(), left.rows(), Bitmap.Config.ARGB_8888);
    Bitmap bmpR = Bitmap.createBitmap(right.cols(), right.rows(), Bitmap.Config.ARGB_8888);

    while (true) {
       //ensuring frames from both cams
        try {
            synchronized (obL) {
                obL.wait();
            }
            synchronized (obR) {
                obR.wait();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        if (frameL == null || frameR == null) continue;

        isProcessing = true;

        //adding frame data to Mats
        left.put(0, 0, frameL);
        Log.d(TAG, "Left: " + left.toString());

        right.put(0, 0, frameR);
        Log.d(TAG, "Right: " + right.toString());

        /* Test Code. Frames are fine and can save them as PNG and see the image
        Utils.matToBitmap(left, bmpL);
        Utils.matToBitmap(right, bmpR);


        saveImage(bmpL, "L");
        saveImage(bmpR,"R");

        bmpL.recycle();
        bmpR.recycle();
        */

        // Below line always produces 0x0 mat  
        // sample info: Mat [ 0*0*CV_8UC1, isCont=false, isSubmat=false, nativeObj=0xffffffffb4b2e7b0, dataAddr=0x0 ]
        Mat result = NativeStitcherWrapper.stitch(mats, false, false);

        isProcessing = false;
    }
}

I am using OpenCV Stitcher.cpp for stitching and here is relevant C++ code being called via JNI

jclass matClass = env->FindClass("org/opencv/core/Mat");
jmethodID getNativeAddr = env->GetMethodID(matClass, "getNativeObjAddr", "()J");

int numImgs = env->GetArrayLength(jInputArray);

vector<Mat> natImgs;
for (int i = 0; i < numImgs; ++i) {
    natImgs.push_back(
            *(Mat *) env->CallLongMethod(
                    env->GetObjectArrayElement(jInputArray, i),
                    getNativeAddr
            )
    );
}

/* The core stitching calls: */
Stitcher stitcher = Stitcher::createDefault();

stitcher.setWaveCorrection((bool) waveCorrect);

Ptr<detail::Blender> blender;

if ((bool) multiBand) {
    blender = new detail::MultiBandBlender();
} else {
    blender = new detail::FeatherBlender();
}

stitcher.setBlender(blender);

Mat result;
Stitcher::Status status = stitcher.stitch(natImgs, result);

stringstream ss;

if (status != Stitcher::OK) {
    __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Could not stitch", 1);
}

ss << "status: ";
ss << status;

string str;
str.append("cols: ");

ss << " cols: ";
ss << result.cols;
ss << " rows: ";
ss << result.rows;
string str1 = ss.str();
const char *log = str1.c_str();

__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, log, 1);

// cout << "cols: "<<result.cols&lt;&lt; "="" rows:="" "&lt;<result.rows&lt;&lt;="" endl;<="" p="">

*(Mat *) jResultMat = result;

Appreciate any pointer/suggestions.

2017-02-16 05:26:33 -0600 received badge  Supporter (source)
2017-02-15 01:55:29 -0600 received badge  Enthusiast
2017-02-15 01:55:22 -0600 received badge  Enthusiast
2017-02-15 01:55:20 -0600 received badge  Enthusiast
2017-02-15 01:55:18 -0600 received badge  Enthusiast
2017-02-15 01:55:17 -0600 received badge  Enthusiast
2017-02-15 01:55:15 -0600 received badge  Enthusiast
2017-02-15 01:55:09 -0600 received badge  Enthusiast
2017-02-13 04:06:04 -0600 received badge  Scholar (source)
2017-02-13 03:58:12 -0600 commented answer Loading video files using VideoCapture in Android

Got it finally! My source video is input.mp4. First, I converted that to MJPEG ffmpeg -i input.mp4 -vcodec mjpeg output.mjpeg and then ffmpeg -i output.mjpeg -vocdec output.avi. My bad, initially I read MJPG as MPEG in you reply! Thanks.

2017-02-13 02:07:17 -0600 commented answer Loading video files using VideoCapture in Android

@berak, I tried couple of videos both in AVI and MP4 format with respective extensions to no avail. I don't know how to put MPEG in AVI! I have tried this command ffmpeg -i input.avi -c:v mpeg4 -vtag xvid output.avi to convert the video but video was still not loaded by VideoCapture.

2017-02-11 06:20:50 -0600 commented answer Loading video files using VideoCapture in Android

seems ffmpeg can be used as a plugin to opencv!

2017-02-11 00:42:01 -0600 commented answer Loading video files using VideoCapture in Android

Thanks Berak for these pointer, I'll explore it more.

In fact, end product is stitching/merging multiple streams from cameras connected to an Android tablet via OTG USB hub. I am novice in this area and that is why I have picked up working with couple of offline videos first. I hope my approach is correct?

Great if you could share some links regrading opencv+ffmpeg on Android or anything related to my project! Thanks.

2017-02-10 06:16:24 -0600 asked a question Loading video files using VideoCapture in Android

Hi,

My aim is to load two video files, grabbing the frames from each file and creating a single frame.

I have understood I can use VideoCapture java class to load files and use Mat class to work on individual frames.

I have two AVI files stored at /storage/emulated/0/Download/received_files/<file>.avi. However VideoCapture is unable to open the files.

VideoCapture vc1 = new VideoCapture();
 VideoCapture vc2 = new VideoCapture();

 if (!vc1.open(video1)) {
    Log.e(TAG, "Could not open the video file1");
 } else {
    Log.i(TAG, "Video1 loaded");
 }

 if (!vc2.open(video1)) {
    Log.e(TAG, "Could not open the video file1");
 } else {
    Log.i(TAG, "Video2 loaded");
 }

It always pronts "Could not open ..." message. I have tested the file paths using File.exists and it returns true. What am I missing here?

I am using OpenCV 3.2.0 for Android and Android lollipop.

My Android setup is done properly and I can view the camera in JavaCameraView.