PageRenderTime 117ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/test/opencv/filter_test.cpp

https://gitlab.com/B3h3m0th/ccv
C++ | 25 lines | 23 code | 2 blank | 0 comment | 5 complexity | a2c2027bb7b4ccfe769784564b7fe924 MD5 | raw file
  1. #include "cv.h"
  2. #include "highgui.h"
  3. #include <assert.h>
  4. #include <stdio.h>
  5. int main(int argc, char** argv)
  6. {
  7. assert(argc == 3);
  8. IplImage* image = cvLoadImage(argv[1]);
  9. CvMat* gray = cvCreateMat(image->height, image->width, CV_32FC1);
  10. CvMat* x = cvCreateMat(image->height, image->width, CV_32FC1);
  11. CvMat* kernel = cvCreateMat(101, 101, CV_32FC1);
  12. for (int i = 0; i < image->height; i++)
  13. for (int j = 0; j < image->width; j++)
  14. gray->data.fl[i * gray->cols + j] = image->imageData[i * image->widthStep + j * 3] * 0.1 + image->imageData[i * image->widthStep + j * 3 + 1] * 0.61 + image->imageData[i * image->widthStep + j * 3 + 2] * 0.29;
  15. for (int i = 0; i < kernel->rows; i++)
  16. for (int j = 0; j < kernel->cols; j++)
  17. kernel->data.fl[i * kernel->cols + j] = exp(-((i - kernel->rows / 2) * (i - kernel->rows / 2) + (j - kernel->cols / 2) * (j - kernel->cols / 2)) / 100);
  18. cvFilter2D(gray, x, kernel);
  19. cvSaveImage(argv[2], x);
  20. cvReleaseMat(&gray);
  21. cvReleaseImage(&image);
  22. return 0;
  23. }