Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include "opencv2/core.hpp"
  2. #include <opencv2/ml.hpp>
  3. #include "opencv2/highgui/highgui.hpp"
  4. #include "opencv2/imgproc/imgproc.hpp"
  5.  
  6. #include <cstdio>
  7. #include <vector>
  8. #include <iostream>
  9. #include<vector>
  10.  
  11.  
  12. using namespace std;
  13. using namespace cv;
  14. using namespace cv::ml;
  15.  
  16. // ---The Code from Greek Letter Recognization----
  17. //Comes from KNN Character Rec. Program. https://github.com/MicrocontrollersAndMore/OpenCV_3_KNN_Character_Recognition_Cpp/blob/master/GenData.cpp#L38
  18. // global variables ///////////////////////////////////////////////////////////////////////////////
  19. const int MIN_CONTOUR_AREA = 100;
  20.  
  21. const int RESIZED_IMAGE_WIDTH = 20;
  22. const int RESIZED_IMAGE_HEIGHT = 30;
  23. //////////////////////////////////////
  24.  
  25.  
  26. // /First step. Reading the image.
  27. void ImgRead()
  28. {
  29.     //Clearing previous images.
  30.     //ClearImages(); TODO: Fix it.
  31.  
  32.     //Reading from the data folder. I guess...
  33.     cv::Mat im = cv::imread("C:/Users/Ahmet/Documents/Visual Studio 2017/Projects/OpencvTest/data/testSrc.jpg", CV_LOAD_IMAGE_COLOR);
  34.  
  35.     //If the image attached correctly the im.data value gonna be diff. than 0.
  36.     if (im.data != 0)
  37.     {
  38.         cv::namedWindow("Test_Image", CV_WINDOW_AUTOSIZE);
  39.        
  40.             //Display the image.
  41.             cv::imshow("Test_Image", im);
  42.             cout << "Image Loaded. Press any key..." << endl;
  43.             cout << "U+0391" << endl;
  44.  
  45.  
  46.            
  47.             //Implementing Canny Filter to detect lines of the characters. Hopefull gonna move on after that.
  48.             Mat gray, edge, canIm; //Creation of a new matrix which hold tha image gray.
  49.             cvtColor(im, gray, CV_BGR2GRAY);
  50.  
  51.             Canny(gray, edge, 50, 150, 3);
  52.  
  53.             edge.convertTo(canIm, CV_8U);
  54.             namedWindow("CannyImage", CV_WINDOW_AUTOSIZE);
  55.             imshow("CannyImage", canIm);
  56.  
  57.            
  58.  
  59.             cv::waitKey(0);
  60.  
  61.  
  62.  
  63.     }
  64.     else
  65.     {
  66.         cout << "Error while loading image!" << endl;
  67.     }
  68. }
  69.  
  70.  
  71.  
  72.  
  73. int main()
  74. {
  75.     /*
  76.     Mat image = imread("C:/Users/Ahmet/Documents/Classes/Fall 2017/AI/Project/Datasets/epfl_corridor/20141008_141323_00/rgb000355.png", IMREAD_COLOR);
  77.    
  78.    
  79.  
  80.     Ptr<SVM> svm = SVM::create();
  81.  
  82.  
  83.     namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
  84.     imshow("test_image", image);
  85.     waitKey(0);
  86.     */
  87.  
  88.  
  89.     //float labels[4] = { 1.0, -1.0, -1.0, -1.0 };
  90.    
  91.  
  92.  
  93.     ImgRead();
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement