I am working on connecting a camera feed using MFC in Visual Studio.
After creating a picture box, I made buttons for open, live, and close.
When I press the open button, the camera connects, and the close button disconnects the camera.
The part where I got stuck is implementing the feature to view the live camera feed when I press the live button.
When I press the live button, I get an alert that says “failed to retrieve grab result.”
I don’t know if this is an issue with the ‘Live’ code or if it’s related to the frame capture code.
My ‘Live’ code :
void Cimageviewer12Dlg::OnBnClickedButtonLive()
{
if (!m_isCameraConnected)
{
AfxMessageBox(_T("Camera is not connected. Please connect the camera first."));
return;
}
try
{
if (!InitializeCamera())
{
AfxMessageBox(_T("Failed to initialize camera."));
return;
}
while (true)
{
BYTE* pFrameData = nullptr;
try
{
pFrameData = CaptureFrame();
}
catch (const GenICam_3_1_Basler_pylon::RuntimeException& e)
{
CString errorMsg;
errorMsg.Format(_T("Failed to capture image from camera: %s"), e.what());
AfxMessageBox(errorMsg);
break;
}
if (pFrameData == nullptr)
{
AfxMessageBox(_T("Failed to capture image from camera."));
break;
}
DisplayFrame(pFrameData);
if (GetAsyncKeyState(VK_ESCAPE))
break;
Sleep(30);
}
}
catch (const GenICam_3_1_Basler_pylon::RuntimeException& e)
{
CString errorMsg;
errorMsg.Format(_T("An error occurred: %s"), e.what());
AfxMessageBox(errorMsg);
}
ReleaseCamera();
}
I can confirm that there was no problem connecting the camera through the Pylon Viewer app.
If there’s anything I’m missing (or assuming), I’d appreciate it if you could let me know.
Sanghyeon Woo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.