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

Setting VideoCapture to certain square resolutions results in garbled output #99

Open
dev-sda1 opened this issue Aug 25, 2023 · 0 comments

Comments

@dev-sda1
Copy link

I'm currently using OpenCV on a Pi 4 with the ArmV7L native library loaded. When I try to capture an image through the Pi Camera with square resolutions from 700x700 to 790x790 in increments of 10, the image is completely garbled. Setting the capture to a non-square resolution like 700x730 results in a clear image.

Square resolutions tried that result in a garbled image:

  • 700x700
  • 710x710
  • 720x720
  • 730x730
  • 740x740
  • 750x750
  • 760x760
  • 770x770
  • 780x780
  • 790x790

Expected result: The image shouldn't be garbled, with whatever's in shot clearly visible.
colour
grey

What actually happens: The image is a garbled mess, nothing is visible.
colour
grey

Reproduction Code:

try {
        VideoCapture camera = new VideoCapture(0);
        camera.set(Videoio.CAP_PROP_FRAME_WIDTH, 700);
        camera.set(Videoio.CAP_PROP_FRAME_HEIGHT, 700);
        if (camera.isOpened()) {
          Mat image = new Mat();
          MatOfByte buffer = new MatOfByte();
          if(colour) {
            camera.read(image);
            Imgcodecs.imencode(".jpg", image, buffer);
          }else{
            camera.read(image);
            Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2GRAY);
            Imgcodecs.imencode(".jpg", image, buffer);
          }

          // Converting the mat into a BufferedImage
          this.image = ImageIO.read(new ByteArrayInputStream(buffer.toArray()));
        }

        camera.release();
    }catch(Exception e){
        e.printStackTrace();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant