Skip to content

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

Description

@dev-sda1

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();
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions