MCPcopy Create free account
hub / github.com/WallBreaker2/op / BuildTemplateTestData

Function BuildTemplateTestData

tests/opencv_test.cpp:202–245  ·  view source on GitHub ↗

构造测试用的大图和模板文件。

Source from the content-addressed store, hash-verified

200
201// 构造测试用的大图和模板文件。
202void BuildTemplateTestData(
203 std::vector<uchar> &source_bgra,
204 int &source_width,
205 int &source_height,
206 int &template_x,
207 int &template_y,
208 int &template_width,
209 int &template_height,
210 std::wstring &template_path) {
211 source_width = 8;
212 source_height = 8;
213 source_bgra.assign(static_cast<size_t>(source_width * source_height * 4), 0);
214
215 for (int y = 0; y < source_height; ++y) {
216 for (int x = 0; x < source_width; ++x) {
217 const size_t index = static_cast<size_t>((y * source_width + x) * 4);
218 source_bgra[index + 0] = static_cast<uchar>((x * x * 17 + y * 29 + x * y * 7 + 23) % 251);
219 source_bgra[index + 1] = static_cast<uchar>((x * 31 + y * y * 19 + x * y * 11 + 47) % 253);
220 source_bgra[index + 2] = static_cast<uchar>((x * 13 + y * 17 + x * x * 5 + y * y * 3 + 71) % 255);
221 source_bgra[index + 3] = 255;
222 }
223 }
224
225 template_x = 3;
226 template_y = 2;
227 template_width = 3;
228 template_height = 3;
229
230 std::vector<uchar> template_bgra(static_cast<size_t>(template_width * template_height * 4), 0);
231 for (int y = 0; y < template_height; ++y) {
232 for (int x = 0; x < template_width; ++x) {
233 const size_t source_index =
234 static_cast<size_t>(((template_y + y) * source_width + (template_x + x)) * 4);
235 const size_t template_index = static_cast<size_t>((y * template_width + x) * 4);
236 for (int channel = 0; channel < 4; ++channel) {
237 template_bgra[template_index + channel] = source_bgra[source_index + channel];
238 }
239 }
240 }
241
242 const auto template_bmp = test_support::BuildBmp32TopDown(template_width, template_height, template_bgra);
243 template_path = test_support::GetTempBmpPath(L"opencv_template_match.bmp");
244 ASSERT_TRUE(WriteBytesToFile(template_path, template_bmp));
245}
246
247// 构造更适合 ORB 的随机纹理块测试数据。
248void BuildFeaturePatternData(

Callers 1

TESTFunction · 0.85

Calls 3

BuildBmp32TopDownFunction · 0.85
GetTempBmpPathFunction · 0.85
WriteBytesToFileFunction · 0.85

Tested by

no test coverage detected