int main(int argc, char *argv[]) { vx_status status = VX_FAILURE; vx_context context = vxCreateContext(); if (argc < 2) { usage(argv[0]); goto relCtx; } vx_char *srcfilename = argv[1]; printf("src img: %s\n", srcfilename); FILE *fp = fopen(srcfilename, "r"); if (!fp) { goto relCtx; } char pgmstr[1024]; unsigned int n; n = fread(pgmstr, 1, sizeof(pgmstr), fp); if (n != sizeof(pgmstr)) { goto relClose; } const char delim = '\n'; const char *token = NULL; unsigned int width, height; // PGM P5 magic string token = strtok(pgmstr, &delim); // PGM author token = strtok(NULL, &delim); // PGM image size token = strtok(NULL, &delim); sscanf(token, "%u %u", &width, &height); printf("width:%u height:%u\n", width, height); status = vxGetStatus((vx_reference)context); if (status != VX_SUCCESS) { fprintf(stderr, "error: vxCreateContext\n"); goto relClose; } vx_rectangle_t rect = {1, 1, width + 1, height + 1}; vx_uint32 i = 0; vx_image images[] = { vxCreateImage(context, width + 2, height + 2, VX_DF_IMAGE_U8), // 0:input vxCreateImageFromROI(images[0], &rect), // 1:ROI input vxCreateImage(context, width, height, VX_DF_IMAGE_U8), // 2:box vxCreateImage(context, width, height, VX_DF_IMAGE_U8), // 3:gaussian vxCreateImage(context, width, height, VX_DF_IMAGE_U8), // 4:alpha vxCreateImage(context, width, height, VX_DF_IMAGE_S16),// 5:add }; vx_float32 a = 0.5f; vx_scalar alpha = vxCreateScalar(context, VX_TYPE_FLOAT32, &a); status |= vxLoadKernels(context, "openvx-tiling"); status |= vxLoadKernels(context, "openvx-debug"); if (status != VX_SUCCESS) { fprintf(stderr, "error: vxLoadKernels %d\n", status); goto relImg; } vx_graph graph = vxCreateGraph(context); status = vxGetStatus((vx_reference)context); if (status != VX_SUCCESS) { fprintf(stderr, "error: vxGetStatus\n"); goto relKern; } ax_node_t axnodes[] = { { vxFReadImageNode(graph, srcfilename, images[1]), "Read" }, { vxTilingBoxNode(graph, images[1], images[2], 5, 5), "Box" }, { vxFWriteImageNode(graph, images[2], "ot_box.pgm"), "Write" }, { vxTilingGaussianNode(graph, images[1], images[3]), "Gaussian" }, { vxFWriteImageNode(graph, images[3], "ot_gauss.pgm"), "Write" }, { vxTilingAlphaNode(graph, images[1], alpha, images[4]), "Alpha" }, { vxFWriteImageNode(graph, images[4], "ot_alpha.pgm"), "Write" }, { vxTilingAddNode(graph, images[1], images[4], images[5]), "Add" }, { vxFWriteImageNode(graph, images[5], "ot_add.pgm"), "Write" }, }; for (i = 0; i < dimof(axnodes); i++) { if (axnodes[i].node == 0) { fprintf(stderr, "error: Failed to create node[%u]\n", i); status = VX_ERROR_INVALID_NODE; goto relNod; } } status = vxVerifyGraph(graph); if (status != VX_SUCCESS) { fprintf(stderr, "error: vxVerifyGraph %d\n", status); goto relNod; } status = vxProcessGraph(graph); if (status != VX_SUCCESS) { fprintf(stderr, "error: vxProcessGraph %d\n", status); goto relNod; } // perf timings vx_perf_t perf_node; vx_perf_t perf_graph; vxQueryGraph(graph, VX_GRAPH_ATTRIBUTE_PERFORMANCE, &perf_graph, sizeof(perf_graph)); axPrintPerf("Graph", &perf_graph); for (i = 0; i < dimof(axnodes); ++i) { vxQueryNode(axnodes[i].node, VX_NODE_ATTRIBUTE_PERFORMANCE, &perf_node, sizeof(perf_node)); axPrintPerf(axnodes[i].name, &perf_node); } relNod: for (i = 0; i < dimof(axnodes); i++) { vxReleaseNode(&axnodes[i].node); } vxReleaseGraph(&graph); relKern: relImg: for (i = 0; i < dimof(images); i++) { vxReleaseImage(&images[i]); } relClose: fclose(fp); relCtx: vxReleaseContext(&context); printf("%s::main() returns = %d\n", argv[0], status); return (int)status; }
static vx_status VX_CALLBACK vxHarrisInitializer(vx_node node, vx_reference parameters[], vx_uint32 num) { vx_status status = VX_FAILURE; if (num == dimof(harris_kernel_params)) { vx_image src = (vx_image)parameters[0]; vx_scalar str = (vx_scalar)parameters[1]; vx_scalar min = (vx_scalar)parameters[2]; vx_scalar sen = (vx_scalar)parameters[3]; vx_scalar win = (vx_scalar)parameters[4]; vx_scalar blk = (vx_scalar)parameters[5]; vx_array arr = (vx_array)parameters[6]; vx_scalar num_corners = (vx_scalar)parameters[7]; vx_context c = vxGetContext((vx_reference)node); vx_graph g = vxCreateGraph(c); vxLoadKernels(c, "openvx-extras"); vxLoadKernels(c, "openvx-debug"); if (g) { vx_uint32 i = 0; vx_int32 ds = 4; vx_scalar shift = vxCreateScalar(c, VX_TYPE_INT32, &ds); vx_image virts[] = { vxCreateVirtualImage(g, 0, 0, VX_DF_IMAGE_VIRT), // Gx vxCreateVirtualImage(g, 0, 0, VX_DF_IMAGE_VIRT), // Gy vxCreateVirtualImage(g, 0, 0, VX_DF_IMAGE_VIRT), // Score vxCreateVirtualImage(g, 0, 0, VX_DF_IMAGE_VIRT), // Suppressed vxCreateVirtualImage(g, 0, 0, VX_DF_IMAGE_U8), // Shifted Suppressed Log10 }; vx_node nodes[] = { vxSobelMxNNode(g, src, win, virts[0], virts[1]), vxHarrisScoreNode(g, virts[0], virts[1], sen, blk, virts[2]), vxEuclideanNonMaxNode(g, virts[2], str, min, virts[3]), vxImageListerNode(g, virts[3], arr, num_corners), #if defined(OPENVX_DEBUGGING) vxConvertDepthNode(g,virts[3],virts[4],VX_CONVERT_POLICY_WRAP,shift), vxFWriteImageNode(g,virts[4],"oharris_strength_power_up4.pgm"), #endif }; status = VX_SUCCESS; status |= vxAddParameterToGraphByIndex(g, nodes[0], 0); // src status |= vxAddParameterToGraphByIndex(g, nodes[2], 1); // str status |= vxAddParameterToGraphByIndex(g, nodes[2], 2); // min status |= vxAddParameterToGraphByIndex(g, nodes[1], 2); // sen status |= vxAddParameterToGraphByIndex(g, nodes[0], 1); // win status |= vxAddParameterToGraphByIndex(g, nodes[1], 3); // blk status |= vxAddParameterToGraphByIndex(g, nodes[3], 1); // arr status |= vxAddParameterToGraphByIndex(g, nodes[3], 2); // num_corners for (i = 0; i < dimof(nodes); i++) { vxReleaseNode(&nodes[i]); } for (i = 0; i < dimof(virts); i++) { vxReleaseImage(&virts[i]); } vxReleaseScalar(&shift); status |= vxVerifyGraph(g); VX_PRINT(VX_ZONE_INFO, "Status from Child Graph = %d\n", status); if (status == VX_SUCCESS) { status = vxSetChildGraphOfNode(node, g); } else { vxReleaseGraph(&g); } } } return status; }