簡體   English   中英

無法保存從網絡攝像頭捕獲的圖像(使用 OpenCV 2.3 寫入編譯錯誤)

[英]Can't save an image captured from webcam (imwrite compile error with OpenCV 2.3)

我正在使用 OpenCV 2.3 制作簡單的網絡攝像頭程序,但被編譯錯誤卡住了。 任何想法將不勝感激。

編譯后,我在 imwrite 收到以下錯誤(在下面的代碼中讀取 function)。

這個使用 imwrite 保存圖像的示例適用於我的環境,這表明 OpenCV 2.3 中的 imwrite 應該適用於我的環境。

錯誤:

error: invalid initialization of reference of type ‘const cv::_InputArray&’ from expression of type ‘cv::Mat*’
/usr/local/include/opencv2/highgui/highgui.hpp:110: error: in passing argument 2 of ‘bool cv::imwrite(const std::string&, const cv::_InputArray&, const std::vector<int, std::allocator<int> >&)’

代碼摘錄:

#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace std;
using namespace cv;

//IplImage* SampleClassA::dispImg = NULL;
Mat* SampleClassA::dispImg = NULL;

int read()
{
        Mat* sharedImg;
    sharedImg = getFrame();
    if (sharedImg)
    {
        if (dispImg == NULL)
        {
            SampleClassA::dispImg = sharedImg;
        }
        Mat outMat;
        outMat = imwrite("./out/sample.jpg", sharedImg);
    }
    sleep(100);
    return 1;
}

Mat* getFrame()
//IplImage* ReadRealTime::getFrame()
{
    if (!capture.isOpened()) // Actual capturing part is omitted here.
    {
        return NULL;
    }
    Mat frame;
    capture >> frame;
    return &frame;
}
</code>

順便說一句,我很困惑 imwrite 是需要 2 arguments 還是 3。以下鏈接和我機器上的 highgui.hpp 都說 3 args,但我上面引用的示例代碼( 來自 ros.org )只使用 2(這是因為我我也在做同樣的事情)。 http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite

附言。 如果您訂閱它,請原諒我在這里發布與我發送到 OpenCV@yahoogroups.com 的問題相同的問題。 我這樣做的原因是因為這個網站對於各種目的來說似乎更具交互性和方便性。

第三個參數是可選的(格式相關參數的數組)。 您收到的錯誤是因為“sharedImage”的類型為 Mat*,無法自動轉換為 imwrite 的預期類型“const cv::_InputArray&”。 如果更仔細地看這個例子,你會發現作為 second 傳入的參數的類型實際上是一個“Mat”(不是一個 Mat*)。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM