#include "opencv\cv.h"
#include "opencv\highgui.h"
#include <iostream>
using namespace cv;
using namespace std;
#define fname "image/b.jpg"
void grey();
int resize(int ht, int wt);
int edge1();
static void onTrackbar(int, void*);
int main(int argc, char** argv)
{
cout<<"Image Location:"<<fname;
IplImage* img = cvLoadImage(fname);
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
cout<<"\nGrey conversion..";
grey();
cvWaitKey(0);
cout<<"\n\nEnter pizel size for resize:";
int ht,wt;
cin>>ht;
cin>>wt;
resize(ht,wt);
cvWaitKey(0);
edge1();
cout<<"image saved successfully";
return 0;
}
void grey()
{
char * file = fname;
IplImage * img2 = cvLoadImage(file, CV_LOAD_IMAGE_GRAYSCALE);
cvSaveImage("output/grey.jpg", img2);
cvNamedWindow( "Grey", CV_WINDOW_AUTOSIZE );
cvShowImage("Grey", img2);
cvWaitKey(0);
cvDestroyWindow("Grey");
cvReleaseImage(&img2);
}
int resize(int ht, int wt)
{
IplImage* inputImage = cvLoadImage("output/grey.jpg");
IplImage* resizedImageLinear =cvCreateImage(cvSize(ht,wt),inputImage->depth, inputImage->nChannels);
cvResize(inputImage, resizedImageLinear, CV_INTER_LINEAR);
cvSaveImage("resize/resized.jpg", resizedImageLinear);
cvNamedWindow("Linear");
cvShowImage("Linear", resizedImageLinear);
cvWaitKey(0);
cvDestroyWindow("Linear");
cvReleaseImage(&resizedImageLinear);
return 0;
}
int edgeThresh = 1;
Mat image, gray, edge, cedge;
static void onTrackbar(int, void*)
{
blur(gray, edge, Size(3,3));
Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
cedge = Scalar::all(0);
image.copyTo(cedge, edge);
imshow("Edge map", cedge);
imwrite("edge.jpg",cedge);
}
int edge1()
{
image = imread(fname, 1);
if(image.empty())
{
printf("Cannot read image file");
return -1;
}
cedge.create(image.size(), image.type());
cvtColor(image, gray, CV_BGR2GRAY);
namedWindow("Edge map", 1);
createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
onTrackbar(0, 0);
waitKey(0);
return 0;
}
#include "opencv\highgui.h"
#include <iostream>
using namespace cv;
using namespace std;
#define fname "image/b.jpg"
void grey();
int resize(int ht, int wt);
int edge1();
static void onTrackbar(int, void*);
int main(int argc, char** argv)
{
cout<<"Image Location:"<<fname;
IplImage* img = cvLoadImage(fname);
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
cout<<"\nGrey conversion..";
grey();
cvWaitKey(0);
cout<<"\n\nEnter pizel size for resize:";
int ht,wt;
cin>>ht;
cin>>wt;
resize(ht,wt);
cvWaitKey(0);
edge1();
cout<<"image saved successfully";
return 0;
}
void grey()
{
char * file = fname;
IplImage * img2 = cvLoadImage(file, CV_LOAD_IMAGE_GRAYSCALE);
cvSaveImage("output/grey.jpg", img2);
cvNamedWindow( "Grey", CV_WINDOW_AUTOSIZE );
cvShowImage("Grey", img2);
cvWaitKey(0);
cvDestroyWindow("Grey");
cvReleaseImage(&img2);
}
int resize(int ht, int wt)
{
IplImage* inputImage = cvLoadImage("output/grey.jpg");
IplImage* resizedImageLinear =cvCreateImage(cvSize(ht,wt),inputImage->depth, inputImage->nChannels);
cvResize(inputImage, resizedImageLinear, CV_INTER_LINEAR);
cvSaveImage("resize/resized.jpg", resizedImageLinear);
cvNamedWindow("Linear");
cvShowImage("Linear", resizedImageLinear);
cvWaitKey(0);
cvDestroyWindow("Linear");
cvReleaseImage(&resizedImageLinear);
return 0;
}
int edgeThresh = 1;
Mat image, gray, edge, cedge;
static void onTrackbar(int, void*)
{
blur(gray, edge, Size(3,3));
Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
cedge = Scalar::all(0);
image.copyTo(cedge, edge);
imshow("Edge map", cedge);
imwrite("edge.jpg",cedge);
}
int edge1()
{
image = imread(fname, 1);
if(image.empty())
{
printf("Cannot read image file");
return -1;
}
cedge.create(image.size(), image.type());
cvtColor(image, gray, CV_BGR2GRAY);
namedWindow("Edge map", 1);
createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
onTrackbar(0, 0);
waitKey(0);
return 0;
}
No comments:
Post a Comment