Skip to content

stitcher doesn't remove the black area #44

Open

Description

@indra365

panorama stitcher doesn't crop the result image to remove that black area

Activity

  1. indra365 commented on Mar 8, 2019

    @indra365
    Author

    Need to convert this code to Java, since javacv doesn't have an easy way to access the pixel ..

    //find largest roi
    bool cropLargestPossibleROI(const cv::Mat& gray, cv::Mat& pano, cv::Rect startROI)
    {
        // evaluate start-ROI
        Mat possibleROI = gray(startROI);
        bool topOk = checkRow(possibleROI, 0);
        bool leftOk = checkColumn(possibleROI, 0);
        bool bottomOk = checkRow(possibleROI, possibleROI.rows-1);
        bool rightOk = checkColumn(possibleROI, possibleROI.cols-1);
        if(topOk && leftOk && bottomOk && rightOk)
        {
            // Found!!
            LOGE("cropLargestPossibleROI success");
            pano = pano(startROI);
            return true;
        }
        // If not, scale ROI down
        Rect newROI(startROI.x, startROI.y, startROI.width, startROI.height);
        // if x is increased, width has to be decreased to compensate
        if(!leftOk)
        {
            newROI.x++;
            newROI.width--;
        }
        // same is valid for y
        if(!topOk)
        {
            newROI.y++;
            newROI.height--;
        }
        if(!rightOk)
        {
            newROI.width--;
        }
        if(!bottomOk)
        {
            newROI.height--;
        }
        if(newROI.x + startROI.width < 0 || newROI.y + newROI.height < 0)
        {
            //sorry...
            LOGE("cropLargestPossibleROI failed");
            return false;
        }
        return cropLargestPossibleROI(gray,pano,newROI);
    }
    
    /check row
    bool checkRow(const cv::Mat& roi, int y)
    {
        int zeroCount = 0;
        for(int x=0; x<roi.cols; x++)
        {
            if(roi.at<uchar>(y, x) == 0)
            {
                zeroCount++;
            }
        }
        if((zeroCount/(float)roi.cols)>cutBlackThreshold)
        {
            return false;
        }
        return true;
    }
    
    //check col
    bool checkColumn(const cv::Mat& roi, int x)
    {
        int zeroCount = 0;
        for(int y=0; y<roi.rows; y++)
        {
            if(roi.at<uchar>(y, x) == 0)
            {
                zeroCount++;
            }
        }
        if((zeroCount/(float)roi.rows)>cutBlackThreshold)
        {
            return false;
        }
        return true;
    }
  2. saudet commented on Mar 8, 2019

    @saudet
    Member
  3. begiflow commented on Nov 18, 2022

    @begiflow

    Hi @indra365 Are you done with this things, Can you share the code crop the black area,.. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions