Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stitcher doesn't remove the black area #44

Open
indra365 opened this issue Mar 4, 2019 · 3 comments
Open

stitcher doesn't remove the black area #44

indra365 opened this issue Mar 4, 2019 · 3 comments

Comments

@indra365
Copy link

indra365 commented Mar 4, 2019

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

@indra365
Copy link
Author

indra365 commented Mar 8, 2019

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

@saudet
Copy link
Member

saudet commented Mar 8, 2019 via email

@chubecode
Copy link

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
Projects
None yet
Development

No branches or pull requests

3 participants