Hello,
I'm trying to pull resized frames of the video feed from my ZWO camera and run opencv algorithms on them.
To do that, I need to take the image buffer from ASIGetVideoData() and translate it into a cv::Mat variable. At the moment I'm simply saving the cv::Mat image to a file. Unfortunately, my images look like this, which is not correct.
Here is my code, which I've simplified by removing variables and function wrappers. The most important lines are in the second-to-last code block. I only have 1 camera which is always ID=0.
int iNumofConnectCameras = ASIGetNumOfConnectedCameras();
if (iNumofConnectCameras > 0) {
cout << "Connected to the camera(s)";
}
else cout << "Failed to connect to the camera(s)";
ASIOpenCamera(0);
ASIInitCamera(0);
ASISetControlValue(0, ASI_HIGH_SPEED_MODE, 1, ASI_FALSE); //Sets to high-speed mode
ASISetROIFormat(0, 640, 480, 2, ASI_IMG_RAW8); //640x480 image, 2 bins
ASIStartVideoCapture(0);
unsigned char img_data[307200]; //480 * 640, image size for ASI_IMG_RAW8
ASIGetVideoData(0, img_data, 307200, -1);
cv::Mat img = cv::Mat(480, 640, CV_8U, img_data);
cv::imwrite("C:\\Users\\lynch\\Desktop\\HVITiltedCameraImages\\test\\img78.png", img);
ASIStopVideoCapture(0);
ASICloseCamera(0);
The code compiles, the camera connects succesfully, and closes correctly. But the image I'm getting is wrong. What am I missing?
I've also tried to copy the exact methodology used in the SDK, which is to pass 'ConnectCamera[ID].pTempImg->imageData' into ASIGetVideoData(), then use memcpy() to copy the data into SaveImage.pBuf , and then save a BMP image with SaveBMP(). In that case, I am getting a solid grey or solid white image, which is also incorrect. (using the ZWO software I can see that the camera is filming an object).
What am I misunderstanding? Is ASISetROIFormat() causing this problem somehow? Or is cv::Mat the problem? I've been googling this for a week and am still stuck.
Thank you in advance.