TransWikia.com

opencv can't open file: /storage/emulated/0/test.mp4 in virtual void cv::videostab::{anonymous}::VideoFileSourceImpl::reset()

Stack Overflow Asked by MrHuang on December 27, 2021

I want to use opencv-videostab to improve video stability on android device. I have run the code successfully by using NDK,but when I try to use the VideoFileSource to read the file,it is not working but the throwing
below error.

cv::error(): OpenCV(3.4.2-dev) Error: No Error (can't open file: /storage/emulated/0/test.mp4) in virtual void cv::videostab::{anonymous}::VideoFileSourceImpl::reset(), file /build/3_4_pack-android/opencv/modules/videostab/src/frame_source.cpp, line 71

But the file actually exits and has got the necessary the permissions.
Can anyone help me find out the issue here. This is very important to me.

My cpp source code:

stability(JNIEnv *env, jclass clazz,jstring inputPath, jstring outputPath) {

    Ptr<IFrameSource> stabilizedFrames;

    const char *input = env->GetStringUTFChars(inputPath, NULL);
    const char *output = env->GetStringUTFChars(outputPath, NULL);

    string a = input;
    try {
        Ptr<VideoFileSource> source = makePtr<VideoFileSource>(input);
        cout << "frame count (rough): " << source->count() << endl;

        double min_inlier_ratio = 0.1;
        Ptr<MotionEstimatorRansacL2> est = makePtr<MotionEstimatorRansacL2>(MM_AFFINE);
        RansacParams ransac = est->ransacParams();
        ransac.size = 3;
        ransac.thresh = 5;
        ransac.eps = 0.5;
        est->setRansacParams(ransac);
        est->setMinInlierRatio(min_inlier_ratio);

        int nkps = 1000;
        Ptr<GFTTDetector> feature_detector = GFTTDetector::create(nkps);

        Ptr<KeypointBasedMotionEstimator> motionEstBuilder = makePtr<KeypointBasedMotionEstimator>(
                est);
        motionEstBuilder->setDetector(feature_detector);
        Ptr<IOutlierRejector> outlierRejector = makePtr<NullOutlierRejector>();
        motionEstBuilder->setOutlierRejector(outlierRejector);
        StabilizerBase *stabilizer = 0;
        bool isTwoPass = 1;
        int radius_pass = 15;
        if (isTwoPass) {
            bool est_trim = true;
            TwoPassStabilizer *twoPassStabilizer = new TwoPassStabilizer();
            twoPassStabilizer->setEstimateTrimRatio(est_trim);
            twoPassStabilizer->setMotionStabilizer(makePtr<GaussianMotionFilter>(radius_pass));
            stabilizer = twoPassStabilizer;
        } else {
            OnePassStabilizer *onePassStabilizer = new OnePassStabilizer();
            onePassStabilizer->setMotionFilter(makePtr<GaussianMotionFilter>(radius_pass));
            stabilizer = onePassStabilizer;
        }
        int radius = 15;
        double trim_ratio = 0.1;
        bool incl_constr = false;
        stabilizer->setFrameSource(source);
        stabilizer->setMotionEstimator(motionEstBuilder);
        stabilizer->setRadius(radius);
        stabilizer->setTrimRatio(trim_ratio);
        stabilizer->setCorrectionForInclusion(incl_constr);
        stabilizer->setBorderMode(BORDER_REPLICATE);
        stabilizedFrames.reset(dynamic_cast<IFrameSource *>(stabilizer));


        VideoWriter writer;
        Mat stabilizedFrame;
        int nframes = 0;
        double outputFps = 25;
        while (!(stabilizedFrame = stabilizedFrames->nextFrame()).empty()) {
            nframes++;
            if (!writer.isOpened())
                writer.open(output, VideoWriter::fourcc('X', 'V', 'I', 'D'), outputFps,
                            stabilizedFrame.size());
            writer << stabilizedFrame;
            imshow("stabilizedFrame", stabilizedFrame);
            char key = static_cast<char>(waitKey(3));
            if (key == 27) {
                cout << endl;
                break;
            }
        }
        cout << "processed frames: " << nframes << endl;
        cout << "finished " << endl;


//        processing(stabilizedFrames, outputPath);
    }
    catch (const exception &e) {
        cout << "error: " << e.what() << endl;
        stabilizedFrames.release();
        return ;
    }

    env->ReleaseStringUTFChars(inputPath, input);
    env->ReleaseStringUTFChars(outputPath, output);
    stabilizedFrames.release();

}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP