visual studio - I am using Open cv for creating RGB to HSI then doing a histogram. Then Fourier transform and back to HSI to RGB -


i can not debug programme. going convert rgb hsi , put histogram in channel. before fourier , after fourier.

#include "stdafx.h" #include <opencv2/opencv.hpp> #include <opencv\highgui.h> #include <iostream> // ass.cpp : converts given rgb image hsi colour space //           performs fourier filtering on particular channel. //  using namespace std; using namespace cv;  // declarations of 4 unfinished functions mat rgb2hsi(const mat& rgb);  // converts rgb image hsi space mat hsi2rgb(const mat& hsi);  // converts hsi image rgb space mat histogram(const mat& im); // returns histogram of selected channel in hsi space // void filter(mat& im);//          // performs frequency-domain filtering on single-channel image  int main(int argc, char* argv[]) {     if (argc < 2) // check number of arguments     {         cerr << "feed me something!!" << endl; // no arguments passed         return -1;     }     string path = argv[1];     mat im; // load rgb image     mat hsi = rgb2hsi(im); // convert hsi space     mat slices[3]; // 3 channels of converted hsi image     im = imread(path); //try load path     if (im.empty()) // loaded sucessfully     {          cerr << "i cannot load file : ";             return -1;     }     imshow("before", im);      split(hsi, slices); // split packed hsi image array of matrices      mat& h = slices[0];     mat& s = slices[1];     mat& = slices[2]; // references h, s, , layers     mat hist1, hist2; // histogram of selected channel before , after filtering 

going apply histogram. may miss header. draw not taken.

    mat histogram(const mat& im)     {         mat hist;         const float range[] = { 0, 255 };         const int channels[] = { 0 };         const int bins = range[1] - range[0];         const int dims[] = { bins, 1 };         const size binsize(2, 240);         const float* ranges[] = { range };          // calculate histogram         calchist(&im, 1, channels, mat(), hist, 1, dims, ranges);          mat draw = mat::zeros(binsize.height, binsize.width * bins, cv_8uc3);         double maxval;         minmaxloc(hist, null, &maxval, 0, 0);          (int b = 0; b < bins; b++)         {             float val = hist.at<float>(b, 0);             int x0 = binsize.width * b;             int y0 = draw.rows - val / maxval * binsize.height + 1;             int x1 = binsize.width * (b + 1) - 1;             int y1 = draw.rows - 1;              rectangle(draw,0, cv::(point(x0, y0), cv::point(x1, y1)), scalar::all(255), cv_filled);         }          return draw;     }     imwrite("input-original.png", rgb); // write input image imwrite("hist-original.png", histogram(h)); // write histogram of selected channel filter(h); // perform filtering merge(slices, 3, hsi); // combine separated h, s, , layers big packed matrix rgb = hsi2rgb(hsi); // convert hsi rgb colour space imwrite("input-filtered.png", rgb); // write filtered image imwrite("hist-filtered.png", histogram(h)); // , histogram of filtered channel  return 0; }    mat rgb2hsi(const mat& rgb) {     mat slicesrgb[3];     mat sliceshsi[3];      mat &r = slicesrgb[0], &g = slicesrgb[1], &b = slicesrgb[2];     mat &h = sliceshsi[0], &s = sliceshsi[1], &i = sliceshsi[2];      split(rgb, slicesrgb);      //     // todo: implement colour conversion rgb => hsi     //     // begin of conversion code     h = r * 1.0f;     s = g * 1.0f;     = b * 1.0f;     // end of conversion code      mat hsi;     merge(sliceshsi, 3, hsi);      return hsi; }  mat hsi2rgb(const mat& hsi) {     mat slicesrgb[3];     mat sliceshsi[3];      mat &r = slicesrgb[0], &g = slicesrgb[1], &b = slicesrgb[2];     mat &h = sliceshsi[0], &s = sliceshsi[1], &i = sliceshsi[2];      split(hsi, sliceshsi);       // begin of conversion code     r = h * 1.0f;     g = s * 1.0f;     b = * 1.0f;     // end of conversion code      mat rgb;     merge(slicesrgb, 3, rgb);      return rgb; }  mat histogram(const mat& im) {     mat hist;     const float range[] = { 0, 255 };     const int channels[] = { 0 };     const int bins = range[1] - range[0];     const int dims[] = { bins, 1 };     const size binsize(2, 240);     const float* ranges[] = { range };      // calculate histogram     calchist(&im, 1, channels, mat(), hist, 1, dims, ranges);      mat draw = mat::zeros(binsize.height, binsize.width * bins, cv_8uc3);     double maxval;     minmaxloc(hist, null, &maxval, 0, 0);      (int b = 0; b < bins; b++)     {         float val = hist.at<float>(b, 0);         int x0 = binsize.width * b;         int y0 = draw.rows - val / maxval * binsize.height + 1;         int x1 = binsize.width * (b + 1) - 1;         int y1 = draw.rows - 1;          rectangle(draw, point(x0, y0), point(x1, y1), scalar::all(255), cv_filled);     }      return draw; }  void filter(mat& im) {     int type = im.type();      // convert pixel data unsigned 8-bit integers (0~255)     //  32-bit floating numbers, required cv::dft     if (type != cv_32f) im.convertto(im, cv_32f);      // perform 2-d discrete fourier transform     mat f;     dft(im, f, dft_complex_output + dft_scale); // dft      // separate packed complex matrix 2 matrices     mat complex[2];     mat& real = complex[0]; // real part     mat& imag = complex[1]; // imaginary part     split(f, complex); // dft(im) => {real,imag}      // frequency domain filtering     int xc = im.cols / 2; // find (xc,yc) highest     int yc = im.rows / 2; //  frequency component      (int y = 0; y < im.rows; y++) // go through each row..     {         (int x = 0; x < im.cols; x++) // through each column..         {             //             // todo: design formula here decide if component             //       discarded or kept.             //             if (false) // override condition             {                 real.at<float>(y, x) = 0;                 imag.at<float>(y, x) = 0;             }         }     }      // pack real , imaginary parts      //  2-channel matrix     merge(complex, 2, f); // {real,imag} => f      // perform 2-d inverse discrete fourier transform     idft(f, im, dft_real_output); // idft      // convert im it's original type     im.convertto(im, type); } 

error list

1 intellisense: expected ';' d:\709 tutorial\dibya_project\dibya_project\dibya_project.cpp 48 2 dibya_project 2 intellisense: identifier "draw" undefined d:\709 tutorial\dibya_project\dibya_project\dibya_project.cpp 70 13 dibya_project 3 intellisense: no instance of overloaded function "rectangle" matches argument list argument types are: (, int, , cv::scalar_, int) d:\709 tutorial\dibya_project\dibya_project\dibya_project.cpp 72 4 dibya_project 4 intellisense: expected identifier d:\709 tutorial\dibya_project\dibya_project\dibya_project.cpp 72 26 dibya_project 5 intellisense: no instance of constructor "cv::point_<tp>::point [with _tp=int]" matches argument list argument types are: (, double __cdecl (double _x)) d:\709 tutorial\dibya_project\dibya_project\dibya_project.cpp 72 27 dibya_project

broken here (in mat histogram(...)):

rectangle(draw,0, cv::(point(x0, y0), cv::point(x1, y1)), scalar::all(255), cv_filled); 

should either:

rectangle(draw,0, cv::rect(point(x0, y0), cv::point(x1, y1)), scalar::all(255), cv_filled); 

or:

rectangle(draw,0, point(x0, y0), cv::point(x1, y1), scalar::all(255), cv_filled); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -