I have configure an Openc CV include file path in Tool Setting, but it still gives warning in my code.
warning is :
Unresolved inclusion: <highgui.h>
my code is :
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
You need to use a different include if you work with cv::Mat:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
Related
The source image, it's result by gray converting from opencv.
cvtColor(img,COLOR_BGR2GRAY);
How I can convert this image to target:
histogram equalization function can be used to distribute intensity values range equally.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
/** #function main */
int main( int argc, char** argv )
{
Mat src, dst;
char* source_window = "Source image";
char* equalized_window = "Equalized Image";
/// Load image
src = imread( "path_to_image", CV_LOAD_IMAGE_GRAYSCALE );
/// Convert to grayscale
//cvtColor( src, src, CV_BGR2GRAY );
/// Apply Histogram Equalization
equalizeHist( src, dst );
/// Display results
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
namedWindow( equalized_window, CV_WINDOW_AUTOSIZE );
imshow( source_window, src );
imshow( equalized_window, dst );
/// Wait until user exits the program
waitKey(0);
return 0;
}
I am new to opencv .I am trying to read video mp4 file but my code always says cannot open video device or file. I have placed video file in code folder .
VideoCapture capture;
capture.open("a.mp4"); // Open file
if (!capture.isOpened())
{
cout << "Cannot open video device or file!" << endl;
getch();
return -1;
}
Mat frame;
namedWindow("video", CV_WINDOW_AUTOSIZE);
while(true)
{
capture >> frame;
if (frame.empty())
break;
imshow("video", frame);
if (waitKey(30) == 'q')
break;
}
I am posting this answer in case someone came across this question as I did.
I was facing almost the same problem, trying to open a video file. My code worked with .avi but failed to open files with .mp4 files.
Turns out openCV needs ffmpeg decoder to be installed on the system. In case of windows OS, you will need to copy opencv_ffmpeg2411.dll file into C:\Windows\System32 directory. The DLL different systems can be found in OpenCV extracted directory.
Hope this helps someone.
this is correct code for video and image reading. I don't know what was the exact error. But using different code from orieally help me do my task in a different way.
// newproject.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "highgui.h"
#include <stdio.h>
#include <cv.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[])
{
//Image Reading
IplImage* img = cvLoadImage( "b.jpg" );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
//Video Reading
// cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
// CvCapture* capture = cvCreateFileCapture( "video.avi" );
// IplImage* frame;
/* while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;//if user enter escape key then exit
}*/
//Summarize by sampling
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));
//double fps = cvGetCaptureProperty (capture,CV_CAP_PROP_FPS);
CvVideoWriter *writer = cvCreateVideoWriter("Ayesha",CV_FOURCC('M','J','P','G'),fps,size);
int x=0;
while(1){
x++;
bgr_frame = cvQueryFrame( capture );
if(!bgr_frame)
break;
if(x==19||x==21){
cvShowImage("Example2",bgr_frame);
cvWriteFrame( writer, bgr_frame );
}
if(x==20){
cvShowImage("Example2",bgr_frame);
cvWriteFrame( writer, bgr_frame );
x=0;
}
char c=cvWaitKey(30);
if (c==27) break;
}
cvReleaseVideoWriter( &writer );
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}
Can any one tell what wrong with the below code. I am getting segmentation fault while mouse moving last portion of the image. I am just printing R,G,B value according to the mouse position.
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
Mat image;
char window_name[20]="Pixel Value Demo";
static void onMouse( int event, int x, int y, int f, void* ){
Vec3b pix=image.at<Vec3b>(x,y);
int B=pix.val[0];
int G=pix.val[1];
int R=pix.val[2];
cout<<R<<endl<<G<<endl<<B<<endl;
}
int main( int argc, char** argv )
{
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
image = imread( "src.jpg");
imshow( window_name, image );
setMouseCallback( window_name, onMouse, 0 );
waitKey(0);
return 0;
}
Thanks in advance......
Vec3b pix=image.at<Vec3b>(x,y);
should be :
Vec3b pix=image.at<Vec3b>(y,x); // row,col !!
I have configure all the libraries and path required for running open cv in c/c++ mode in eclipse, i have written the below code, but i don't know how to build and debug,
my code is
#include "cv.h"
#include "highgui.h"
//using namespace cv;
int main(int argc, char *argv[])
{
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
IplImage* img = cvLoadImage("prado.jpg",1);
cvShowImage("Example1", img );//*/
cvWaitKey(0);
return 0;
}
i am running my Project "DisplayImage",Open CV application in eclipse, but i got error in DisplayImage.d under Debug Folder the error is :
make: *** multiple target patterns. Stop.
and my code is :
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
i have successfuly include lib and open cv in project,but i got this error when i try to runs the project