kernel is not defined in this scope?
i am trying to write a code which does image sharpening and i was able to run the program and get the output with
** kernel [-c, -c, -c, -c, 8c+1, -c, -c, -c, -c]
but now i am trying to change the kernel with a trackbar and am getting an error that kernel is not defined in this scope
the code i am working is
i know that this is a lot of code to go but what you need to see is the trackbar declaration and the modeselection trackbar funtion thats all
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int c = 1;
int mode = 0;
int *mode_Address = &mode;
int *c_Address = &c;
int initialsharp = 0;
void modeSelection(int mode)
{
if(mode == 0){
Mat kernel = (Mat_<double>(3,3) << -c, -c, -c, -c, 8*c+1, -c, -c, -c, -c);
}
else if(mode == 1){
Mat kernel = (Mat_<double>(3,3) << 0, 0, 0, -c, 2*c+1, -c, 0, 0, 0);
}
else if(mode == 2){
Mat kernel = (Mat_<double>(3,3) << 0, -c, 0, 0, 2*c+1, 0, 0, -c, 0);
}
else if(mode == 3){
Mat kernel = (Mat_<double>(3,3) << 0, -c, 0, -c, 4*c+1, -c, 0, -c, 0);
}
else if(mode == 4){
Mat kernel = (Mat_<double>(3,3) << -c, 0, 0, 0, 2*c+1, 0, 0, 0, -c);
}
else if(mode == 5){
Mat kernel = (Mat_<double>(3,3) << 0, 0, 0, -c, 2*c+1, 0, -c, 0, 0);
}
else if(mode == 6){
Mat kernel = (Mat_<double>(3,3) << -c, 0, -c, 0, 4*c+1, 0, -c, 0, -c);
}
}
void trackbarPosMode(int pos, void*y)
{
*mode_Address = pos;
modeSelection(mode);
Mat src = imread( "blurry_moon.tif", CV_LOAD_IMAGE_GRAYSCALE );
Mat dst = Mat::zeros( src.size(), src.type() );
filter2D(src, dst, -1, kernel);
imshow("Output", dst);
}
void trackbarPosSharp(int pos, void *y)
{
*c_Address = pos ;
modeSelection(mode);
Mat src = imread( "blurry_moon.tif", CV_LOAD_IMAGE_GRAYSCALE );
Mat dst = Mat::zeros( src.size(), src.type() );
filter2D(src, dst, -1, kernel);
imshow("Output", dst);
}
int main( )
{
Mat src = imread( "blurry_moon.tif", CV_LOAD_IMAGE_GRAYSCALE );
namedWindow( "Original image", CV_WINDOW_AUTOSIZE );
imshow( "Original image", src );
src.release();
namedWindow("Output", CV_WINDOW_AUTOSIZE);
createTrackbar("Shrapening level ","Output", &initialsharp, 20, trackbarPosSharp);
createTrackbar("0:all 1:horizontal 2:vertical 3:Ver&Hor 4:left_diagonal 5:right_diagonal 6:both_Diag","Output", &initialsharp, 6, trackbarPosMode);
trackbarPosSharp(0, 0);
trackbarPosMode(0, 0);
waitKey(0);
return 0;
}
ok, i just figured that i am not returning the matrix which i dont know how to do it or how can i create pointer to matrix, i mean i dont know if it is just like other variables or not. i will post again if i find anything
like below