Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

StereoBM doesn't give proper output

$
0
0
I want to find depth from stereo image. 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. I have tried it in with Java and Python and faced the same issue in both the languages. **Here is my java 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(); } } How can I correct my code so that it will work for all images? **The below images gives expected output** ![image description](https://i.stack.imgur.com/gJ6WX.png) ![image description](https://i.stack.imgur.com/Vc7Vx.png) ![image description](https://i.stack.imgur.com/QrY69.png) **The below images gives incorrect output** ![image description](https://i.stack.imgur.com/dlntZ.jpg) ![image description](https://i.stack.imgur.com/sHLal.jpg) ![image description](https://i.stack.imgur.com/WXdHF.png)

Viewing all articles
Browse latest Browse all 2088

Trending Articles