Use C++ for HSV Colour Space and Fourier Filtering using OpenCV libraries and VI
ID: 3865637 • Letter: U
Question
Use C++ for HSV Colour Space and Fourier Filtering using OpenCV libraries and VISUAL STUDIO
Convert the input image from RGB to HSV colour space. Select a channel among H, S and V, show its histogram. Apply Discrete Fourier Transform on the selected channel, display it and perform necessary operations like re-center the DFT. Apply a filter to the transformed channel in the frequency domain. Transform the filtered channel back to the spatial domain. Make a histogram of the restored channel. Convert the HSV image back to RGB colour space. Observe and try to explain what happened to the input image, with respect to the chosen colour channel and the applied filter.Explanation / Answer
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
VideoCapture cap(0); //capture the video from web cam
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the web cam" << endl;
return -1;
}
namedWindow("Control", CV_WINDOW_AUTOSIZE); //create a window called "Control"
int iLowH = 0;
int iHighH = 179;
int iLowS = 0;
int iHighS = 255;
int iLowV = 0;
int iHighV = 255;
//Create trackbars in "Control" window
cvCreateTrackbar("LowH", "Control", &iLowH, 179); //Hue (0 - 179)
cvCreateTrackbar("HighH", "Control", &iHighH, 179);
cvCreateTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 - 255)
cvCreateTrackbar("HighS", "Control", &iHighS, 255);
cvCreateTrackbar("LowV", "Control", &iLowV, 255); //Value (0 - 255)
cvCreateTrackbar("HighV", "Control", &iHighV, 255);
while (true)
{
Mat imgOriginal;
bool bSuccess = cap.read(imgOriginal); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.