Merge pull request #1480 from berak:fix_paillou_sample

pull/1482/head
Alexander Alekhin 7 years ago
commit b0fc85b1a4
  1. 61
      modules/ximgproc/samples/paillou_demo.cpp

@ -48,23 +48,22 @@ using namespace std;
int aa = 100, ww = 10; int aa = 100, ww = 10;
Ptr<Mat> img;
const char* window_name = "Gradient Modulus"; const char* window_name = "Gradient Modulus";
static void DisplayImage(Mat x,string s) static void DisplayImage(Mat x,string s)
{ {
vector<Mat> sx; vector<Mat> sx;
split(x, sx); split(x, sx);
vector<double> minVal(3), maxVal(3); vector<double> minVal(3), maxVal(3);
for (int i = 0; i < static_cast<int>(sx.size()); i++) for (int i = 0; i < static_cast<int>(sx.size()); i++)
{ {
minMaxLoc(sx[i], &minVal[i], &maxVal[i]); minMaxLoc(sx[i], &minVal[i], &maxVal[i]);
} }
maxVal[0] = *max_element(maxVal.begin(), maxVal.end()); maxVal[0] = *max_element(maxVal.begin(), maxVal.end());
minVal[0] = *min_element(minVal.begin(), minVal.end()); minVal[0] = *min_element(minVal.begin(), minVal.end());
Mat uc; Mat uc;
x.convertTo(uc, CV_8U,255/(maxVal[0]-minVal[0]),-255*minVal[0]/(maxVal[0]-minVal[0])); x.convertTo(uc, CV_8U,255/(maxVal[0]-minVal[0]),-255*minVal[0]/(maxVal[0]-minVal[0]));
imshow(s, uc); imshow(s, uc);
} }
@ -72,38 +71,42 @@ static void DisplayImage(Mat x,string s)
* @function paillouFilter * @function paillouFilter
* @brief Trackbar callback * @brief Trackbar callback
*/ */
static void PaillouFilter(int, void*) static void PaillouFilter(int, void*pm)
{ {
Mat img = *((Mat*)pm);
Mat dst; Mat dst;
double a=aa/100.0,w=ww/100.0; double a=aa/100.0, w=ww/100.0;
Mat rx,ry; Mat rx,ry;
GradientPaillouX(*img.get(),rx,a,w); GradientPaillouX(img, rx, a, w);
GradientPaillouY(*img.get(),ry,a,w); GradientPaillouY(img, ry, a, w);
DisplayImage(rx, "Gx"); DisplayImage(rx, "Gx");
DisplayImage(ry, "Gy"); DisplayImage(ry, "Gy");
add(rx.mul(rx),ry.mul(ry),dst); add(rx.mul(rx), ry.mul(ry), dst);
sqrt(dst,dst); sqrt(dst, dst);
DisplayImage(dst, window_name ); DisplayImage(dst, window_name );
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
Mat *m=new Mat; if (argc < 2)
if (argc == 2) {
*m = imread(argv[1]); cout << "usage: paillou_demo [image]" << endl;
if (m->empty()) return 1;
}
Mat img = imread(argv[1]);
if (img.empty())
{ {
cout << "File not found or empty image\n"; cout << "File not found or empty image\n";
return 1;
} }
img = Ptr<Mat>(m); imshow("Original",img);
imshow("Original",*img.get());
namedWindow( window_name, WINDOW_AUTOSIZE ); namedWindow( window_name, WINDOW_AUTOSIZE );
/// Create a Trackbar for user to enter threshold /// Create a Trackbar for user to enter threshold
createTrackbar( "a:",window_name, &aa, 400, PaillouFilter ); createTrackbar( "a:",window_name, &aa, 400, PaillouFilter, &img );
createTrackbar( "w:", window_name, &ww, 400, PaillouFilter ); createTrackbar( "w:", window_name, &ww, 400, PaillouFilter, &img );
PaillouFilter(0,NULL); PaillouFilter(0, &img);
waitKey(); waitKey();
return 0; return 0;
} }

Loading…
Cancel
Save