Panorama-OpticalFlow icon indicating copy to clipboard operation
Panorama-OpticalFlow copied to clipboard

malloc() core dump error while iterating.

Open dagata-mining opened this issue 3 years ago • 7 comments

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 avatar Nov 16 '21 00:11 dagata-mining

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

dagata-mining avatar Nov 16 '21 01:11 dagata-mining

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.

MungoMeng avatar Nov 16 '21 03:11 MungoMeng

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;
        }

´´´

´´´

dagata-mining avatar Nov 16 '21 04:11 dagata-mining

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.

MungoMeng avatar Nov 16 '21 04:11 MungoMeng

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..

dagata-mining avatar Nov 16 '21 05:11 dagata-mining

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.)

MungoMeng avatar Nov 16 '21 05:11 MungoMeng

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

dagata-mining avatar Nov 16 '21 14:11 dagata-mining