/test/opencv/sobel_test.cpp

https://gitlab.com/B3h3m0th/ccv · C++ · 30 lines · 26 code · 4 blank · 0 comment · 1 complexity · 64806dd7d30abe6d9cdd8931ad558d76 MD5 · raw file

  1. #include "cv.h"
  2. #include "highgui.h"
  3. #include <assert.h>
  4. #include <stdio.h>
  5. #include <sys/time.h>
  6. unsigned int get_current_time()
  7. {
  8. struct timeval tv;
  9. gettimeofday(&tv, NULL);
  10. return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  11. }
  12. int main(int argc, char** argv)
  13. {
  14. assert(argc == 3);
  15. IplImage* image = cvLoadImage(argv[1]);
  16. CvMat* gray = cvCreateMat(image->height, image->width, CV_8UC1);
  17. CvMat* x = cvCreateMat(image->height, image->width, CV_32FC1);
  18. cvCvtColor(image, gray, CV_BGR2GRAY);
  19. unsigned int elapsed_time = get_current_time();
  20. cvSobel(gray, x, 1, 0, 1);
  21. printf("elapsed time : %d\n", get_current_time() - elapsed_time);
  22. cvSaveImage(argv[2], x);
  23. cvReleaseMat(&gray);
  24. cvReleaseImage(&image);
  25. return 0;
  26. }