I have seen many posts regarding this issue but this one is different. My code is working for one pair of an image but not working for another pair of an image.
Later, I want to convert video inputs from two cameras into a stereo output. I have tried that but that also have the same issue as the images (second pair of images) shown below.
The below images gives expected output
The below images gives incorrect output
How can I correct my code so that it will work for all images?
Here is my code
public static void main(String[] args)
{
Mat left = Imgcodecs.imread("path", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
Mat right = Imgcodecs.imread("path", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
Core.normalize(left, left, 0, 255, NORM_MINMAX, CvType.CV_8U);
Core.normalize(right, right, 0, 255, NORM_MINMAX, CvType.CV_8U);
StereoBM bm = StereoBM.create(16, 15);
Mat disparity = new Mat();
bm.compute(left, right, disparity);
ImageProcessor.showResult(disparity);
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void showResult(Mat img)
{
Imgproc.resize(img, img, new Size(640, 480));
MatOfByte matOfByte = new MatOfByte();
Imgcodecs.imencode(".jpg", img, matOfByte);
byte[] byteArray = matOfByte.toArray();
BufferedImage buffImage = null;
try
{
InputStream in = new ByteArrayInputStream(byteArray);
buffImage = ImageIO.read(in);
JFrame frame = new JFrame();
frame.getContentPane().add(new JLabel(new ImageIcon(buffImage)));
frame.pack();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
} catch (IOException e)
{
e.printStackTrace();
}
}





