MungoMeng / Panorama-OpticalFlow

Panorama stitching based on asymmetric bidirectional optical flow
MIT License
87 stars 19 forks source link

malloc() core dump error while iterating. #4

Closed dagata-mining closed 1 year ago

dagata-mining commented 2 years ago

Hi MungoMeng, Thanks for the optical flow integration

I've been struggling for the past few days trying to integrate your algorithm. I have successfully integrated the algorithm (CPU version) into my processing. I am stitching 6 images at the time for a 360vr video, but when I loop for the next set of images I'm gettting a mAlloc core dump error. Looks like there is some kind of leak somewhere but can't find where... The only thing I've noticed is that my swap is continuously increasing.. Any advice on that?

dagata-mining commented 2 years ago

Swap seems to increase when the flowAlg->computeOpticalFlow() function is called

MungoMeng commented 2 years ago

Hi Dagata, Sorry I am not sure what happened in your processing. I didn't meet this problem before. This code is quite old and I have not touched it for 4 years. It's reasonable that the swap is increasing when the computeOpticalFlow() function is called. Nevertheless, after the call, I deleted the flowAlg, which releases the memory.

dagata-mining commented 2 years ago

Yes, I've been investigating that... Anyway here's a bit of my code.. The first iteration works great but when I do this inside a parent loop it crashes....

´´´cpp

        for (size_t i = 0 ; i+1 < imagePairs.size(); i++)
        {
            UERROR("Loop : %i",i);
            int pair1 = imagePairs[i][0];
            int pair2 = imagePairs[i][1];

           // OPTICAL FLOW
            std::vector<cv::Mat> channels2;
            cv::split(individualRGBs[pair1], channels2);
            channels2.push_back(masks[pair1]);
            cv::merge(channels2, rgbaRight);

            std::vector<cv::Mat> channels1;
            cv::split(individualRGBs[pair2], channels1);
            channels1.push_back(masks[pair2]);
            cv::Mat rgbaLeft;
            cv::merge(channels1, rgbaLeft);

            stitch_tools::Stitchtools Stools;
            cv::cvtColor(rgbaRight , rgbaRight , cv::COLOR_BGR2BGRA);
            cv::cvtColor(rgbaLeft, rgbaLeft, cv::COLOR_BGR2BGRA);
            Stools.prepare(rgbaLeft, rgbaRight);

            cv::Mat overlappedL = Stools.getOverlappedL();
            cv::Mat overlappedR = Stools.getOverlappedR();
            cv::Mat blend = Stools.getBlend();

            optical_flow::NovelViewGenerator* novelViewGen =
                                                         new optical_flow::NovelViewGeneratorAsymmetricFlow("pixflow_search_20");
            novelViewGen->prepare(rgbaLeft, rgbaRight);

            novelViewGen->setBlend(blend);
            cv::Mat novelViewMerged = cv::Mat();
            novelViewGen->generateNovelView(novelViewMerged);

            Stools.setMergedmiddle(novelViewMerged);
            Stools.Gather();
            cv::Mat result(Stools.getFinalResult());

            delete novelViewGen;
        }

´´´

´´´

MungoMeng commented 2 years ago

I identified an error. The "novelViewGen->prepare(rgbaLeft, rgbaRight)" should be "novelViewGen->prepare(overlappedL, overlappedR)", because optical flow only needs to be computed in the overlapped area.

But I am not sure whether or why this error caused the core dump. You can just have a try.

dagata-mining commented 2 years ago

Gave it a try but still I have a core dump... I really like the results, it keeps crashing on me... I think its related to a cv::Mat() not being properly allocated, somewhere in the code..

MungoMeng commented 2 years ago

Sorry, I really don't know why it keeps crashing. Maybe you can just run my code without any modification to see whether it works. If no work, maybe your environment has some problems (package version mismatch, etc.)

dagata-mining commented 2 years ago

Thanks for the help I'll run it as third party!