0

I am getting the four corner of the image using this code:

cv::Mat CVSquares::detectedSquaresInImage (cv::Mat image, float tol, int threshold, int levels, int acc)
{
    vector<vector<Point> > squares;

    if( image.empty() )
        {
        cout << "CVSquares.m: Couldn't load " << endl;
        }

    tolerance = tol;
    thresh = threshold;
    N = levels;
    accuracy = acc;
    findSquares(image, squares);
    //drawSquares(image, squares);

    // The largest of them probably represents the paper
    vector<Point> largest_square;
    find_largest_square(squares, largest_square);
    drawSquares(image, largest_square);

    // Print the x,y coordinates of the square
    cout << "Point 1: " << largest_square[0] << endl;
    cout << "Point 2: " << largest_square[1] << endl;
    cout << "Point 3: " << largest_square[2] << endl;
    cout << "Point 4: " << largest_square[3] << endl;

    return image;
}

Its giving me four points but now I want to crop the image to that point. Can anyone please help me with this?

I have tried to use code from this answer

But its display error below.

duplicate symbol __Z9getCenterNSt3__16vectorIN2cv6Point_IiEENS_9allocatorIS3_EEEE in:
    /Users/user/Library/Developer/Xcode/DerivedData/OpenCVSquares-gbnzjrefuxhjlchibreeqqdoaiqq/Build/Intermediates/OpenCVSquares.build/Debug-iphonesimulator/OpenCVSquares.build/Objects-normal/i386/UIImage+OpenCV.o
    /Users/user/Library/Developer/Xcode/DerivedData/OpenCVSquares-gbnzjrefuxhjlchibreeqqdoaiqq/Build/Intermediates/OpenCVSquares.build/Debug-iphonesimulator/OpenCVSquares.build/Objects-normal/i386/CVSquares.o
duplicate symbol __Z25sortSquarePointsClockwiseNSt3__16vectorIN2cv6Point_IiEENS_9allocatorIS3_EEEE in:
    /Users/user/Library/Developer/Xcode/DerivedData/OpenCVSquares-gbnzjrefuxhjlchibreeqqdoaiqq/Build/Intermediates/OpenCVSquares.build/Debug-iphonesimulator/OpenCVSquares.build/Objects-normal/i386/UIImage+OpenCV.o
    /Users/user/Library/Developer/Xcode/DerivedData/OpenCVSquares-gbnzjrefuxhjlchibreeqqdoaiqq/Build/Intermediates/OpenCVSquares.build/Debug-iphonesimulator/OpenCVSquares.build/Objects-normal/i386/CVSquares.o
ld: 2 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Community
  • 1
  • 1

3 Answers3

0

Suppose your four end points are x1,y1,x2,y2

Then using the code

src.copyTo(dst(Rect(x1,y1,x1+x2,y1+y2));
Haris
  • 13,645
  • 12
  • 90
  • 121
0

using copyTo plus the ROI rect is ok, sample code like this:

Mat srcImg = imread('sample.jpg'), dstImg;
Rect rect = Rect( x, y, width, height ); // ROI rect in srcImg
// In your case, x=x1, y=y1, width=x2-x1, height=y2-y1; 
// (x1, y1) is the up-left corner, (x2, y2) is the bottom-right corner
srcImg(rect).copyTo(dstImg);  

Hope this'll help.

Mr. Sun Lin
  • 1,099
  • 9
  • 13
0
$ c++filt __Z9getCenterNSt3__16vectorIN2cv6Point_IiEENS_9allocatorIS3_EEEE

getCenter(std::__1::vector, std::__1::allocator > >)

$ c++filt __Z25sortSquarePointsClockwiseNSt3__16vectorIN2cv6Point_IiEENS_9allocatorIS3_EEEE

sortSquarePointsClockwise(std::__1::vector, std::__1::allocator > >)

This is a linking error. It suggested that you defined the each of the above functions twice.

lanpa
  • 1,319
  • 9
  • 12