1. Homepage
  2. Programming
  3. COMP27112 Introduction to Visual Computing Coursework Assignment 3 Image Processing Exercise 1

COMP27112 Introduction to Visual Computing Coursework Assignment 3 Image Processing Exercise 1

Engage in a Conversation
C++Computer VisionImage ProcessingCOMP27112Introduction to Visual ComputingUKUniversity Of Manchester

COMP27112 Introduction to Visual Computing CourseNana.COM

Coursework Assignment 3 Image Processing Exercise 1

Introduction

The aim of this exercise is to get you started with OpenCV and to do some very simple image processing. CourseNana.COM

OpenCV (opencv.org) is an open source computer vision and machine learning library that’s released under the BSD licence. It can be used freely for academic and commercial purposes. The first version was released in 2001, it now has a user community of over 47,000 users and the libraries have been downloaded over 18 million times. CourseNana.COM

Since it’s a well-established and widely used library, there are a lot of resources on the internet. If you run into problems with the coursework, this should be one of the first places to seek help. Other useful websites are listed in Blackboard. CourseNana.COM

This piece of coursework is worth 7.5% of the unit’s assessment, so you should spend no more than about 7.5 hours on it. CourseNana.COM

Getting Started

Follow the instructions on the Coursework area of Blackboard to download and install the version of OpenCV for your operating system. In this lab, you’ll write two simple programmes, one to prove to yourself that you’ve installed OpenCV correctly, the second to perform thresholding. CourseNana.COM

Hello OpenCV

To check that everything is working correctly, print out the installed OpenCV major and minor versions in the console. To do that, OpenCV provides two macros representing the two integers: CV_MAJOR_VERSION and CV_MINOR_VERSION. CourseNana.COM

Use your favourite text editor to create a new C++ file. (Although this is technically a C++ file, you’re using the C subset only.) Type the following code: CourseNana.COM

#include <stdio.h>
#include <opencv2/core/core.hpp>
int main(int argc, char ∗argv[])
{
//Print the OpenCV version
printf ("OpenCV version: %d.%d\n", CV_MAJOR_VERSION,
CV_MINOR_VERSION);
return 0;
}

Now compile it by running: CourseNana.COM

g++ HelloCV.cpp -o HelloCV ’pkg-config --cflags --libs
opencv4’

(If you copy and paste, then be aware of the problem with quotation marks.) Run the output programme, you should get: CourseNana.COM

OpenCV version 4.5 CourseNana.COM

You can, of course, make editing and compiling much easier by using an IDE, instructions for doing that can be found on the web. CourseNana.COM

Using OpenCV

The first part of this exercise is to load an image file into memory and display it in a window using OpenCV. Along with the standard input/output library, and core.hpp that was included in the example you will also need to include the highgui.hpp headers. core.hpp provides basic OpenCV structures and operations, while highgui.hpp gives you the ability to create and work with windows to display information to the user. CourseNana.COM

First, you will need to provide the code with an image path, either by using command-line arguments, user input in the terminal or any other way that you can think of. Make sure to check that the path has been provided, if it hasn’t you should exit the program. Now that you have a path to the image, you need to load the image. For this, OpenCV has a function named imread() in the cv namespace which takes the path as the first argument and some flags that determine how the data is interpreted as the second (it’s safest to use IMREAD_UNCHANGED). You can find all the details in the OpenCV documentation, links are given below. This function loads the image into a cv::Mat object. Now that you have the image (you should check that the image is loaded, if imread fails, it will return NULL), you need a window to display it in. OpenCV has a function called cv::namedWindow() which does this for you. This takes the window name as the first argument and the window flags as the second argument. You want the window size to match the image size, so use CV_WINDOW_AUTOSIZE as the flag. All that’s left is to add the image to the window. cv::imshow() does just that. The first argument is the name of the window you want to add the image to and the second argument is a pointer to the image. At this point, if you compile and run the program you will notice that nothing shows (try it). That is because your program terminates and closes the window before you can see anything. A useful command in this case is cv::waitKey(0). The function waits for the user to press a key in order to move on with the code. The numerical argument defines how long the function will wait, look up the documentation to see how it’s interpreted. Compile and run the code. A window should pop up with the title that you gave and the image. CourseNana.COM

Note that you must also include the imgcodecs.hpp header to use imread. CourseNana.COM

To summarise, the steps involved are: CourseNana.COM

  1. Load an image using imread()
  2. If imread has returned NULL, the reading has failed, so exit the programme.
  3. Create a display window using namedWindow
  4. Load the image into that window using imshow
  5. Use waitKey to pause the execution until a key is pressed

The final step in this lab is to threshold the image and display the result. If you loaded a colour image, you must first convert it to an 8-bit grey scale image using cv::cvtColor which takes four arguments: the input and output images, a flag that indicates the conversion being used (use COLOR_BGR2GRAY) and the last one indicates the number of channels in the output (use 0). Thresholding is achieved using the function cv::threshold. You will need to include imgproc.hpp to use threshold. CourseNana.COM

Threshold takes five arguments: the input and output images, a value for the threshold, a maxval and a flag to indicate the type of thresholding being applied. You will probably use THRESH_OTSU as the flag – in this case the function returns the value of the threshold that’s computed and maxval is ignored. If you set the flag to THRESH_BINARY, then CourseNana.COM

maxval if src(x, y) > thresh dst(x, y) = * 0 otherwise CourseNana.COM

Finally, save the threshold image using cv::imwrite() CourseNana.COM

You might want to try to add a trackbar to control the thresholding to see the effect of different thresholds. CourseNana.COM

Finally, apply the thresholding programme to the sample images that are provided. CourseNana.COM

Queries

Experiment with your code to find the answers to the following questions. Write your answers in a separate document. CourseNana.COM

  1. Is Otsu’s method successful in thresholding all the images?
  2. How would you modify the thresholding algorithm to address any problems?
  3. What metrics are there for assessing the success of thresholding?

Submission

Once you have a working solution, simply ZIP the C++ file and your answer document and submit it to the Lab 3 area in Blackboard. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
C++代写,Computer Vision代写,Image Processing代写,COMP27112代写,Introduction to Visual Computing代写,UK代写,University Of Manchester代写,C++代编,Computer Vision代编,Image Processing代编,COMP27112代编,Introduction to Visual Computing代编,UK代编,University Of Manchester代编,C++代考,Computer Vision代考,Image Processing代考,COMP27112代考,Introduction to Visual Computing代考,UK代考,University Of Manchester代考,C++help,Computer Visionhelp,Image Processinghelp,COMP27112help,Introduction to Visual Computinghelp,UKhelp,University Of Manchesterhelp,C++作业代写,Computer Vision作业代写,Image Processing作业代写,COMP27112作业代写,Introduction to Visual Computing作业代写,UK作业代写,University Of Manchester作业代写,C++编程代写,Computer Vision编程代写,Image Processing编程代写,COMP27112编程代写,Introduction to Visual Computing编程代写,UK编程代写,University Of Manchester编程代写,C++programming help,Computer Visionprogramming help,Image Processingprogramming help,COMP27112programming help,Introduction to Visual Computingprogramming help,UKprogramming help,University Of Manchesterprogramming help,C++assignment help,Computer Visionassignment help,Image Processingassignment help,COMP27112assignment help,Introduction to Visual Computingassignment help,UKassignment help,University Of Manchesterassignment help,C++solution,Computer Visionsolution,Image Processingsolution,COMP27112solution,Introduction to Visual Computingsolution,UKsolution,University Of Manchestersolution,