I am using the following code to get images from the Raspberry Pi 4 camera (Pi Camera V2, OpenCV 4.5):
#include <opencv2/opencv.hpp>
using namespace cv;
const int VID_HEIGHT = 1232;
const int VID_WIDTH = 1640;
// const int VID_HEIGHT = 720;
// const int VID_WIDTH = 1280;
int main(){
Mat image;
VideoCapture cap(0);
cap.set(CAP_PROP_FRAME_HEIGHT, VID_HEIGHT);
cap.set(CAP_PROP_FRAME_WIDTH, VID_WIDTH);
if(!cap.isOpened()) {
return -1;
}
cap>>image;
imwrite("test1.jpg", image);
return 0;
}
The problem is, when the image width and height are set to 1640x1232, it writes a garbage image in the file (test1.jpg), shown below:
But if the image width and height are set below 1280x720, the images are correct in the given file. How to fix this problem? I want to use the resolution 1640x1232 because it uses the full FOV of the PI camera.