0

我是opencv的新手,我试图将rgb视频转换为灰度,但它总是给出错误错误LNK2019:函数_wmain中引用的未解析的外部符号_cvCvtColor请告诉我我做错了什么

#include "stdafx.h"
#include "highgui.h"
#include <stdio.h>
#include <cv.h>
#include <tchar.h>
#include <highgui.h>
#include <stdio.h>
#include <conio.h>
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>

#include <iostream>
#include <conio.h>

using namespace cv;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    CvCapture* capture = 0;
    capture = cvCreateFileCapture( "video.avi" );
    if(!capture)
    {
        return -1;
    }
    IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read
    double fps = cvGetCaptureProperty (capture,CV_CAP_PROP_FPS);

    CvSize size = cvSize((int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT));
    CvVideoWriter *writer = cvCreateVideoWriter("izlaz.avi",CV_FOURCC_DEFAULT,fps,size);

    IplImage *grayScaleImage = cvCreateImage(size ,IPL_DEPTH_8U,1);

    while( (bgr_frame=cvQueryFrame(capture)) != NULL )
    {
        cvCvtColor(bgr_frame, grayScaleImage, CV_BGR2GRAY);
        cvWriteFrame( writer, grayScaleImage );
    }

    cvReleaseVideoWriter( &writer );
    cvReleaseCapture( &capture );
}
4

3 回答 3

1

我添加了库 imgproc。我正在使用opencv 2.3。对于本刊

ALT+F7 配置属性->输入->附加依赖->编辑复制这个opencv_imgproc230.lib

于 2013-09-15T12:03:22.473 回答
0

试试这个更新

#包括

#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>


int main (){

cv::Mat frame;
cv::VideoCapture cap("Grabbed video.avi");//("Wildlife.wmv");
int key =0;
cap>>frame;
cv::VideoWriter record("Grabbed2 video.avi",CV_FOURCC('M','J','P','G'), 30,frame.size(), 0);
while(key != 27){
    if(cap.isOpened()){
    cap >>frame;
    if(!frame.empty()){
        cv::cvtColor(frame,frame,CV_BGR2GRAY);
        record<<frame;
        imshow("fvakjb",frame);
    }
    }

    else key =27;
    //cv::cvtColor(frame,frame,CV_BGR2GRAY);




key= cv::waitKey(10);
}
record.release();
cap.release();
return 0;

}

于 2013-09-13T14:13:04.950 回答
0

此外 ,

如果您使用的是 cmake 和 qibuild,您可以尝试以下方法进行链接:

它会自动链接到相应的库并使其标题可用。

qi_use_lib(yourProgramName your libraries)

像这样:

qi_use_lib(getimages ALCOMMON ALPROXIES ALVISION OPENCV2_CORE OPENCV2_HIGHGUI OPENCV2_IMGPROC)
于 2016-04-12T14:56:47.483 回答