MCPcopy Create free account
hub / github.com/HyperInspire/InspireFace / main

Function main

cpp/sample/cpp_api/cpp_sample_inspirecv.cpp:12–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#endif
11
12int main() {
13 // Make directory
14 if (CREATE_DIR("cv") == -1) {
15 // If the directory already exists, it is not an error
16 if (errno != EEXIST) {
17 std::cerr << "Error creating directory" << std::endl;
18 return 1;
19 }
20 }
21
22 /* Image I/O */
23
24 // Load image from file
25 // Load with 3 channels (BGR, like opencv)
26 inspirecv::Image img = inspirecv::Image::Create("test_res/data/bulk/kun_cartoon_crop.jpg", 3);
27
28 // Load image from buffer
29 // uint8_t* buffer = ...; // buffer is a pointer to the image data
30 // bool is_alloc_mem = false; // if true, will allocate memory for the image data,
31 // // false is recommended to point to the original data to avoid copying
32 // inspirecv::Image img_buffer = inspirecv::Image::Create(width, height, channel, buffer, is_alloc_mem);
33
34 // Save image to file
35 img.Write("cv/output.jpg");
36
37 // Show image, warning: it must depend on opencv
38 // img.Show("input");
39
40 // Get pointer to image data
41 const uint8_t* ptr = img.Data();
42
43 /* Image Processing */
44 // Convert to grayscale
45 inspirecv::Image gray = img.ToGray();
46 gray.Write("cv/gray.jpg");
47
48 // Apply Gaussian blur
49 inspirecv::Image blurred = img.GaussianBlur(3, 1.0);
50 blurred.Write("cv/blurred.jpg");
51
52 // Geometric transformations
53 auto scale = 0.35;
54 bool use_bilinear = true;
55 inspirecv::Image resized = img.Resize(img.Width() * scale, img.Height() * scale, use_bilinear); // Resize image
56 resized.Write("cv/resized.jpg");
57
58 // Rotate 90 degrees clockwise
59 inspirecv::Image rotated = img.Rotate90();
60 rotated.Write("cv/rotated.jpg");
61
62 // Flip vertically
63 inspirecv::Image flipped_vertical = img.FlipVertical();
64 flipped_vertical.Write("cv/flipped_vertical.jpg");
65
66 // Flip horizontally
67 inspirecv::Image flipped_horizontal = img.FlipHorizontal();
68 flipped_horizontal.Write("cv/flipped_horizontal.jpg");
69

Callers

nothing calls this directly

Calls 5

SetPreviewSizeMethod · 0.80
ResizeMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected