0% found this document useful (0 votes)
26 views2 pages

Report

The document contains code for 4 tasks that load and manipulate images using OpenCV functions. Task 1 loads an image and displays it in a window. Task 2 loads an image as a matrix and prints it. Task 3 loads a color image, converts it to grayscale, thresholds it, displays and saves the binary image. Task 4 loads a color image, converts it to grayscale, applies Canny edge detection, and displays the edge image.

Uploaded by

Mandeep Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Report

The document contains code for 4 tasks that load and manipulate images using OpenCV functions. Task 1 loads an image and displays it in a window. Task 2 loads an image as a matrix and prints it. Task 3 loads a color image, converts it to grayscale, thresholds it, displays and saves the binary image. Task 4 loads a color image, converts it to grayscale, applies Canny edge detection, and displays the edge image.

Uploaded by

Mandeep Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Task 1

#include <stdio.h>
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/cvaux.h"
#include "opencv/cxmisc.h"
using namespace cv;
using namespace std;

int main(int argc, const char** argv)
{

IplImage* img = cvLoadImage("wp.png", CV_LOAD_IMAGE_COLOR);
cvNamedWindow("opencvtest", CV_WINDOW_AUTOSIZE);
cvShowImage("opencvtest", img);
cvWaitKey(0);
cvReleaseImage(&img);
return 0;
}

Task 2
#include <stdio.h>
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/cvaux.h"
#include "opencv/cxmisc.h"
using namespace cv;
using namespace std;
int main(int argc, const char** argv)
{

Mat img = imread("wp.png", 0);
cout <<img;
return 0;
}



Task 3

#include <stdio.h>
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/cvaux.h"
#include "opencv/cxmisc.h"
using namespace cv;
using namespace std;

int main(int argc, const char** argv)
{

Mat im_gray = imread("wp.png",0);
Mat im_rgb = imread("wp.png");
cvtColor(im_rgb, im_gray, CV_RGB2GRAY);
Mat img_bw = im_gray > 128;
imshow("bw", img_bw);
imwrite("wp_bw.png", img_bw);
waitKey(0);
return 0;
}



Task 4

#include <stdio.h>
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv/cvaux.h"
#include "opencv/cxmisc.h"
using namespace cv;
using namespace std;

int main(int argc, const char** argv)
{
Mat img;
img = imread("wp.png", CV_LOAD_IMAGE_COLOR);
namedWindow("Original image", CV_WINDOW_AUTOSIZE);
imshow("Original image", img);
Mat gray, edge, draw;
cvtColor(img, gray, CV_BGR2GRAY);
Canny(gray, edge, 50, 150, 3);
edge.convertTo(draw, CV_8U);
namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", draw);
waitKey(0);
return 0;
}

You might also like