[英]Can't save an image captured from webcam (imwrite compile error with OpenCV 2.3)
[英]OpenCV imwrite doesn't save the image
我使用的是 Basler 相機,我正在嘗試使用 OpenCV 保存抓取的圖像。 但是,當我嘗試使用 imwrite() 時,出現此錯誤:
imwrite_('C:/Users/Uporabnik/Desktop/slika.png'):無法寫入數據:未知異常
我對抓取的圖像的轉換:
openCvImage = Mat(image.GetHeight(), image.GetWidth(), CV_16U, (uint8_t *)image.GetBuffer());
嘗試保存圖像:
cv::imwrite("C:/Users/Uporabnik/Desktop/slika.png", openCvImage);
我也在使用basler相機。 您還需要共享包含basler配置的代碼。以下是我使用basler相機獲取opencv格式的幀的方法:
#include <pylon/usb/BaslerUsbInstantCamera.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <pylon/PylonIncludes.h>
using namespace std;
using namespace cv;
using namespace Pylon;
using namespace GenApi;
using namespace Basler_UsbCameraParams;
int main()
{
Mat openCvImage;
Pylon::PylonAutoInitTerm autoInitTerm;
CBaslerUsbInstantCamera camera(CTlFactory::GetInstance().CreateFirstDevice());
CImageFormatConverter formatConverter;
CPylonImage pylonImage;
camera.MaxNumBuffer = 1;
formatConverter.OutputPixelFormat= PixelType_BGR8packed;
camera.StartGrabbing( c_countOfImagesToGrab);
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
formatConverter.Convert(pylonImage, ptrGrabResult);
openCvImage= cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult>GetWidth(), CV_8UC3, (uint8_t *) pylonImage.GetBuffer());
imshow("Basler Frame",openCvImage);
waitKey(0);
return 0;
}
但是首先,您需要使用“ imshow”功能來查看圖像。 如果可以,則問題出在您的目錄部分。 否則,您需要共享有關啟動basler攝像機的代碼。
請注意圖像的尺寸,您可以簡單地打印並查看形狀是否正確。 就我而言,我錯誤地將批量尺寸包含到圖像形狀中,並通過 image = image[0] 解決了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.