user2740528
user2740528

Reputation: 35

Fatal Error when converting RGB to gray opencv

I am new to opencv i m trying to convert rgb video to grayscale but it always give error error LNK2019: unresolved external symbol _cvCvtColor referenced in function _wmain Please tell me what i am doing wrong

#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 );
}

Upvotes: 0

Views: 1524

Answers (3)

caglabaran
caglabaran

Reputation: 121

Additionally ,

If you are using cmake and qibuild you can try this for linking :

It automatically links with the corresponding libraries and make their headers available.

qi_use_lib(yourProgramName your libraries)

like this:

qi_use_lib(getimages ALCOMMON ALPROXIES ALVISION OPENCV2_CORE OPENCV2_HIGHGUI OPENCV2_IMGPROC)

Upvotes: 0

user2740528
user2740528

Reputation: 35

I added Library imgproc. I am using opencv 2.3. For this press

ALT+F7 configuration properties -> Input ->Additional dependencies -> Edit and copy this opencv_imgproc230.lib

Upvotes: 1

Engine
Engine

Reputation: 5432

try this UPDATE

#include

#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;

}

Upvotes: 0

Related Questions