////////////////////////////////////////////////////////////////////////// \brief load 4-channel unsigned byte image and convert it to single channel FP32 image \param[out] img_data pointer to raw image data \param[out] img_w image width \param[out] img_h image height \param[out] img_s image row stride \param[in] name image file name \param[in] exePath executable file path \return
| 85 | /// \return true if image is successfully loaded or false otherwise |
| 86 | /////////////////////////////////////////////////////////////////////////////// |
| 87 | bool LoadImageAsFP32(float *&img_data, int &img_w, int &img_h, int &img_s, const char *name, const char *exePath) |
| 88 | { |
| 89 | printf("Loading \"%s\" ...\n", name); |
| 90 | char *name_ = sdkFindFilePath(name, exePath); |
| 91 | |
| 92 | if (!name_) { |
| 93 | printf("File not found\n"); |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | unsigned char *data = 0; |
| 98 | unsigned int w = 0, h = 0; |
| 99 | bool result = sdkLoadPPM4ub(name_, &data, &w, &h); |
| 100 | |
| 101 | if (result == false) { |
| 102 | printf("Invalid file format\n"); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | img_w = w; |
| 107 | img_h = h; |
| 108 | img_s = iAlignUp(img_w); |
| 109 | |
| 110 | img_data = new float[img_s * h]; |
| 111 | |
| 112 | // source is 4 channel image |
| 113 | const int widthStep = 4 * img_w; |
| 114 | |
| 115 | for (int i = 0; i < img_h; ++i) { |
| 116 | for (int j = 0; j < img_w; ++j) { |
| 117 | img_data[j + i * img_s] = ((float)data[j * 4 + i * widthStep]) / 255.0f; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return true; |
| 122 | } |
| 123 | |
| 124 | /////////////////////////////////////////////////////////////////////////////// |
| 125 | /// \brief compare given flow field with gold (L1 norm) |
no test coverage detected