【发布时间】:2022-01-12 15:57:00
【问题描述】:
我是 C++ 的初学者,但我已经使用 Python 使用 OpenCV 进行了一些 blob 检测。但是使用 C++,我什至无法将相机流传送到窗口。
相机为Basler DAA3840-45UC,平台为Win10。
谁能帮我解释为什么“imshow("Smaller", resized_down);"显示空白窗口但“Pylon::DisplayImage(1, ptrGrabResult);”正在显示相机视图?
编辑:我没有在“imshow”之后添加“waitKey”。现在可以了。
PylonInitialize();
try
{
CBaslerUniversalInstantCamera camera(CTlFactory::GetInstance().CreateFirstDevice());
camera.MaxNumBuffer = 5;
camera.StartGrabbing(GrabStrategy_LatestImageOnly);
CGrabResultPtr ptrGrabResult;
while (camera.IsGrabbing()) {
CImageFormatConverter fc;
fc.OutputPixelFormat = PixelType_BGR8packed;
camera.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);
CImageFormatConverter converter;
CPylonImage image;
int scale_percent = 25;
if (ptrGrabResult->GrabSucceeded())
{
fc.Convert(image, ptrGrabResult);
Mat cv_img = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t*)image.GetBuffer());
cv::Size sz = cv_img.size();
int imageWidth = sz.width;
int imageHeight = sz.height;
int down_width = imageWidth * scale_percent / 100;
int down_height = imageHeight * scale_percent / 100;
Mat resized_down;
resize(cv_img, resized_down, Size(down_width, down_height), INTER_LINEAR);
imshow("Smaller", resized_down);
#ifdef PYLON_WIN_BUILD
Pylon::DisplayImage(1, ptrGrabResult);
#endif
【问题讨论】:
-
imshow没有waitKey-- 好像有人没有读过documentation。
标签: c++ opencv computer-vision