// Getting feature map for the selected subimage // // API // int getFeatureMaps(const cv::Mat& image, const int k, featureMap **map); // INPUT // image - selected subimage // k - size of cells // OUTPUT // map - feature map // RESULT // Error status */
| 78 | // Error status |
| 79 | */ |
| 80 | int getFeatureMaps(const cv::Mat& image, const int k, CvLSVMFeatureMapCaskade **map) |
| 81 | { |
| 82 | float kernel[3] = {-1.f, 0.f, 1.f}; |
| 83 | cv::Mat kernel_dx(1, 3, CV_32F, kernel); |
| 84 | cv::Mat kernel_dy(3, 1, CV_32F, kernel); |
| 85 | |
| 86 | float boundary_x[NUM_SECTOR + 1]; |
| 87 | float boundary_y[NUM_SECTOR + 1]; |
| 88 | |
| 89 | int height = image.rows; |
| 90 | int width = image.cols; |
| 91 | |
| 92 | int numChannels = image.channels(); |
| 93 | |
| 94 | int sizeX = width / k; |
| 95 | int sizeY = height / k; |
| 96 | int px = 3 * NUM_SECTOR; |
| 97 | int p = px; |
| 98 | int stringSize = sizeX * p; |
| 99 | allocFeatureMapObject(map, sizeX, sizeY, p); |
| 100 | |
| 101 | cv::Mat dx; |
| 102 | cv::Mat dy; |
| 103 | cv::filter2D(image, dx, CV_32FC3, kernel_dx, cv::Point(-1, 0)); |
| 104 | cv::filter2D(image, dy, CV_32FC3, kernel_dy, cv::Point(0, -1)); |
| 105 | |
| 106 | for (int i = 0; i <= NUM_SECTOR; i++) |
| 107 | { |
| 108 | float arg_vector = ( (float) i ) * ( (float)(PI) / (float)(NUM_SECTOR) ); |
| 109 | boundary_x[i] = cosf(arg_vector); |
| 110 | boundary_y[i] = sinf(arg_vector); |
| 111 | }/*for(i = 0; i <= NUM_SECTOR; i++) */ |
| 112 | |
| 113 | float* r = (float *)malloc( sizeof(float) * (width * height)); |
| 114 | int* alfa = (int *)malloc( sizeof(int ) * (width * height * 2)); |
| 115 | |
| 116 | for (int j = 1; j < height - 1; j++) |
| 117 | { |
| 118 | const float* datadx = dx.ptr<float>(j); |
| 119 | const float* datady = dy.ptr<float>(j); |
| 120 | for (int i = 1; i < width - 1; i++) |
| 121 | { |
| 122 | int c = 0; |
| 123 | float x = (datadx[i * numChannels + c]); |
| 124 | float y = (datady[i * numChannels + c]); |
| 125 | |
| 126 | r[j * width + i] =sqrtf(x * x + y * y); |
| 127 | for(int ch = 1; ch < numChannels; ch++) |
| 128 | { |
| 129 | float tx = (datadx[i * numChannels + ch]); |
| 130 | float ty = (datady[i * numChannels + ch]); |
| 131 | float magnitude = sqrtf(tx * tx + ty * ty); |
| 132 | if(magnitude > r[j * width + i]) |
| 133 | { |
| 134 | r[j * width + i] = magnitude; |
| 135 | c = ch; |
| 136 | x = tx; |
| 137 | y = ty; |
no test coverage detected