I use Java bindings for OpenCvand try to add a border to the cropped image. However, while the border draws at 100%, as expected, in the full image, it does not draw the left side correctly if I crop the original image.
For example: Grumpy Cat

Now, to add a border, I more or less copied the code from the tutorial along the OpenCV border .
eg.
public class main {
public static void main( String[] args )
{
try{
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
Mat source = Highgui.imread("images\\original.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(),source.cols(),source.type());
Imgproc.copyMakeBorder(source, destination, 10, 10,
10, 10, Imgproc.BORDER_CONSTANT, new Scalar(255,0,0));
Highgui.imwrite("images\\borderWrap.jpg", destination);
}
catch (Exception e) {
System.out.println("error: " + e.getMessage());
}
}
}
By running this code, I get a nice border with 10px on each side, as expected.

Now, if I modify the code to crop the image first, it will stop working as expected.
public class main {
public static void main( String[] args )
{
try{
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
Mat isource = Highgui.imread("images\\original.jpg", Highgui.CV_LOAD_IMAGE_COLOR);
Mat source = new Mat(isource, new Rect(0, 0, 480, 540));
Mat destination = new Mat(source.rows(),source.cols(),source.type());
Imgproc.copyMakeBorder(source, destination, 10, 10,
10, 10, Imgproc.BORDER_CONSTANT, new Scalar(255,0,0));
Highgui.imwrite("images\\borderWrap.jpg", destination);
}
catch (Exception e) {
System.out.println("error: " + e.getMessage());
}
}
}

. , - ?
, copyMakeBorder, , , .
Imgproc.copyMakeBorder(source, destination, 10, 10,
10, 10, Imgproc.BORDER_CONSTANT,
new Scalar(255,0,0));
Imgproc.copyMakeBorder(destination, destination, 0, 0,
0, 10, Imgproc.BORDER_CONSTANT,
new Scalar(255,0,0));

- , ?