E
E
elisey4742016-02-07 12:39:22
linux
elisey474, 2016-02-07 12:39:22

What is wrong in my c++ (opencv) code?

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
IplImage* frame=0;
CvCapture* CAMERA_VIEW = cvCreateCameraCapture(0);
assert( CAMERA_VIEW );
cvSetCaptureProperty(CAMERA_VIEW, CV_CAP_PROP_FRAME_WIDTH, 720); 
cvSetCaptureProperty(CAMERA_VIEW, CV_CAP_PROP_FRAME_HEIGHT, 640);
cvNamedWindow("С камеры", CV_WINDOW_AUTOSIZE);
while(true){
frame = cvQueryFrame( CAMERA_VIEW );
cvShowImage("С камеры", frame);
 char c = cvWaitKey(33);
                if (c == 27) {
                        break;
                }

}
cvReleaseCapture( &CAMERA_VIEW );
        cvDestroyWindow("С камеры");
        return 0;
}

It works, displays the image from the camera to me.
Now I want to highlight the pink circles cut out of paper. I read that you need to first convert the image to hsv.
I change the code:
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
IplImage* frame=0;
CvCapture* CAMERA_VIEW = cvCreateCameraCapture(0);
assert( CAMERA_VIEW );
cvSetCaptureProperty(CAMERA_VIEW, CV_CAP_PROP_FRAME_WIDTH, 720); 
cvSetCaptureProperty(CAMERA_VIEW, CV_CAP_PROP_FRAME_HEIGHT, 640);
cvNamedWindow("С камеры", CV_WINDOW_AUTOSIZE);
while(true){
frame = cvQueryFrame( CAMERA_VIEW );
IplImage* frame_hsv=0;
frame_hsv = cvCvtColor( frame, CV_BGR2HSV );
cvShowImage("С камеры", frame);
 char c = cvWaitKey(33);
                if (c == 27) {
                        break;
                }

}
cvReleaseCapture( &CAMERA_VIEW );
        cvDestroyWindow("С камеры");
        return 0;
}

Compiling (gcc Ubuntu 15.10):
prog.cpp: In function 'int main()':
prog.cpp:16:43: error: cannot convert '' to 'CvArr* {aka void*}' for argument '2' to 'void cvCvtColor(const CvArr*, CvArr*, int)'
frame_hsv = cvCvtColor( frame, CV_BGR2HSV );
What's wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel K, 2016-02-07
@PavelK

frame_hsv = cvCvtColor( frame, CV_BGR2HSV );
should be like this:
Dock:
docs.opencv.org/2.4/modules/imgproc/doc/miscellane...

J
jcmvbkbc, 2016-02-07
@jcmvbkbc

The C prototype of this function is --

void cvCvtColor(const CvArr* src, CvArr* dst, int code)
-- what to convert, where to put the result and how to convert. For C++ --
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0 )
, the meaning of the required parameters is the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question