当前位置:   article > 正文

DM8148 开发记录 四 opencv 应用c6accel

DM8148 开发记录 四 opencv 应用c6accel
ezsdk中有opencv的加速,直接测试之

http://software-dl.ti.com/dsps/dsps_public_sw/c6000/web/c6accel/latest/index_FDS.html 下载地址

http://software-dl.ti.com/dsps/dsps_public_sw/ezsdk/index.html

For C6Accel 2.01.00.11 and later


C6Accel 2.01.00.11 intergrates OpenCV functionality on the DSP along with other libraries. This release adds a test application and a new build target 'opencv_app' to build this in the package. There is a pre-requisite to build this opencv_app. This requires users to build OpenCV 2.x for the ARM as described here and place the OpenCV shared libraries on the target filesystem under the path $TARGETFS/usr/lib

After the prequisite step is complete execute make to build and install the OpenCV test application

make opencv_app
make opencv_app_install

 从以上的文字可以看出,要交叉编译opencv,因为,这个工具有做arm 和dsp运算速度的比较。所以要交叉编译opencv。其实这个,貌似不是很有必要,对于有些环节,移植opencv 到a8,都有困难。

我本人也在dm3730上完全移植过opencv 1.0 到codec engine中,改天把四路和代码一起贴出来。

c6accel 做的工作,很方便,不过如果要做优化,也要改动一部分的代码,貌似,源码都是打包好的

下面是dm8148的arm 和dsp 做opencv的耗时比较 的源码

  1. /*================================================================================*/
  2. /* Copyright (c) 2010, Texas Instruments Incorporated */
  3. /* All rights reserved. */
  4. /* */
  5. /* Name: C6Accel_testfxns.c */
  6. /* */
  7. /* Descriptions: */
  8. /* File contains code to test kernels in the C6Accel codec */
  9. /* */
  10. /* Version: 0.0.1 */
  11. /*================================================================================*/
  12. /* This define uses the new frame based (ie row and col parameters) that are optimised for C6Accel
  13. as they only request one operation on all rows rather than row operations*/
  14. #define USE_NEW_FRAME_APIS
  15. /*XDC and codec engine includes*/
  16. #include <xdc/std.h>
  17. #include <ti/sdo/ce/osal/Memory.h>
  18. /* Run Time lib include files: */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdarg.h>
  23. #include <math.h>
  24. //#include "precomp.hpp"
  25. #include <ti/sdo/linuxutils/cmem/src/interface/cmem.h>
  26. /* Declare MACROS that will be used for benchmarking*/
  27. #include "benchmark.h"
  28. /* Include C6ACCEL headers*/
  29. #include "../../c6accelw/c6accelw.h"
  30. #include "../../c6accelw/c6accelw_opencv.h"
  31. // extra headers for OpenCV
  32. /*#include <time.h>
  33. #include <sys/types.h>
  34. #include <sys/time.h>
  35. #include <sys/stat.h>*/
  36. #include "opencv/highgui.h"
  37. #define CVX_GRAY50 cvScalar(100,0,0,0)
  38. #define CVX_WHITE cvScalar(255,0,0,0)
  39. /* Create default heap memory configuration for test functions */
  40. static Memory_AllocParams testfxnsMemParams =
  41. {
  42. Memory_CONTIGHEAP,
  43. Memory_CACHED,
  44. Memory_DEFAULTALIGNMENT,
  45. 0
  46. };
  47. extern CMEM_AllocParams cvCmemParams;// = {CMEM_HEAP, CMEM_CACHED, 8};
  48. /* Test for Floating point kernels */
  49. /*
  50. * Test function for arithmetic rts single precision functions in this function
  51. */
  52. // helper function - get overhead time
  53. static int get_overhead_time(void)
  54. {
  55. struct timeval startTime, endTime;
  56. gettimeofday(&startTime, NULL);
  57. gettimeofday(&endTime, NULL);
  58. return endTime.tv_usec - startTime.tv_usec;
  59. }
  60. Int c6accel_test_cvSobel(C6accel_Handle hC6accel, char *input_file_name, int n)
  61. {
  62. IplImage *inputImg, *outputImg_arm, *outputImg_dsp, *scaleImg_arm, *scaleImg_dsp;
  63. struct timeval startTime, endTime;
  64. int t_overhead, t_algo, i;
  65. float t_avg;
  66. printf("cvSobel Test (%s, %i iterations)\n", input_file_name, n);
  67. // initialize timer
  68. t_overhead = get_overhead_time();
  69. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  70. // 1. Read input image from file
  71. inputImg = cvLoadImage( input_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  72. // 2. Check image depth; require 8-bit
  73. if (inputImg->depth != IPL_DEPTH_8U && inputImg->depth != IPL_DEPTH_8S)
  74. {
  75. printf("C6accel_cvSobel test failed; input image must have 8-bit depth.\n");
  76. return 0;
  77. }
  78. // 3. Allocate output images (must have 16- and 8-bit depth; output MUST be 16S)
  79. outputImg_arm = cvCreateImage(cvSize(inputImg->width, inputImg->height), IPL_DEPTH_16S, 1);
  80. outputImg_dsp = cvCreateImage(cvSize(inputImg->width, inputImg->height), IPL_DEPTH_16S, 1);
  81. scaleImg_arm = cvCreateImage(cvSize(inputImg->width, inputImg->height), IPL_DEPTH_8U, 1);
  82. scaleImg_dsp = cvCreateImage(cvSize(inputImg->width, inputImg->height), IPL_DEPTH_8U, 1);
  83. //printf("outputImage: %x\n", CMEM_getPhys(outputImg_arm));
  84. // printf("outputImagedata: %x\n", CMEM_getPhys(outputImg_arm->imageData));
  85. // 4.a Apply ARM algorithm
  86. cvSobel(inputImg, outputImg_arm, 1, 1, 3); // run once before timing
  87. gettimeofday(&startTime, NULL);
  88. for (i = 0; i < n; i++)
  89. cvSobel(inputImg, outputImg_arm, 1, 1, 3);
  90. gettimeofday(&endTime, NULL);
  91. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  92. t_avg = (float)t_algo / (float)n;
  93. printf("Called ARM Sobel function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  94. // 4.b Apply DSP algorithm
  95. C6accel_cvSobel(hC6accel, inputImg, outputImg_dsp, 1, 1, 3); // run once before timing
  96. gettimeofday(&startTime, NULL);
  97. for (i = 0; i < n; i++)
  98. C6accel_cvSobel(hC6accel, inputImg, outputImg_dsp, 1, 1, 3);
  99. gettimeofday(&endTime, NULL);
  100. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  101. t_avg = (float)t_algo / (float)n;
  102. printf("Called DSP Sobel function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  103. // 5.a Apply scale conversion on ARM
  104. cvConvertScale(outputImg_arm, scaleImg_arm, 0.5, 128); // run once before timing
  105. gettimeofday(&startTime, NULL);
  106. for (i = 0; i < n; i++)
  107. cvConvertScale(outputImg_arm, scaleImg_arm, 0.5, 128);
  108. gettimeofday(&endTime, NULL);
  109. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  110. t_avg = (float)t_algo / (float)n;
  111. printf("Called ARM ConvertScale function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  112. // 5.b Apply scale conversion on DSP
  113. C6accel_cvConvertScale(hC6accel, outputImg_dsp, scaleImg_dsp, 0.5, 128); // run once before timing
  114. gettimeofday(&startTime, NULL);
  115. for (i = 0; i < n; i++)
  116. C6accel_cvConvertScale(hC6accel, outputImg_dsp, scaleImg_dsp, 0.5, 128);
  117. gettimeofday(&endTime, NULL);
  118. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  119. t_avg = (float)t_algo / (float)n;
  120. printf("Called DSP ConvertScale function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  121. // 6. Compare outputs
  122. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(scaleImg_arm, scaleImg_dsp, CV_L2, NULL));
  123. // 7. Save outputs to filesystem
  124. cvSaveImage("./output_arm.png", scaleImg_arm, 0);
  125. cvSaveImage("./output_dsp.png", scaleImg_dsp, 0);
  126. //Free memory as cvFree was not patched during the openCv build
  127. // printf("outputImage: %x\n", CMEM_getPhys(outputImg_arm));
  128. // printf("outputImagedata: %x\n", CMEM_getPhys(outputImg_arm->imageData));
  129. // Freeing memory
  130. cvReleaseImage(&outputImg_arm);
  131. cvReleaseImage(&outputImg_dsp);
  132. cvReleaseImage(&scaleImg_arm);
  133. cvReleaseImage(&scaleImg_dsp);
  134. cvReleaseImage(&inputImg);
  135. printf("C6accel_cvSobel test completed successfully; outputs saved to filesystem\n");
  136. return 1;
  137. }
  138. Int c6accel_test_cvFlip(C6accel_Handle hC6accel, char *input_file_name, int n)
  139. {
  140. IplImage *inputImg, *outputImg_arm, *outputImg_dsp, *copyImg_arm, *copyImg_dsp;
  141. struct timeval startTime, endTime;
  142. int t_overhead, t_algo, i;
  143. float t_avg;
  144. printf("cvFlip Test (%s, %i iterations)\n", input_file_name, n);
  145. // initialize timer
  146. t_overhead = get_overhead_time();
  147. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  148. // 1. Read input image from file
  149. inputImg = cvLoadImage( input_file_name, CV_LOAD_IMAGE_COLOR);
  150. // 2. Allocate output images (must have same depth, channels as input)
  151. outputImg_arm = cvCreateImage(cvSize(inputImg->width, inputImg->height), inputImg->depth, inputImg->nChannels);
  152. outputImg_dsp = cvCreateImage(cvSize(inputImg->width, inputImg->height), inputImg->depth, inputImg->nChannels);
  153. copyImg_arm = cvCreateImage(cvSize(inputImg->width, inputImg->height), inputImg->depth, inputImg->nChannels);
  154. copyImg_dsp = cvCreateImage(cvSize(inputImg->width, inputImg->height), inputImg->depth, inputImg->nChannels);
  155. // 3.a Apply ARM algorithm
  156. cvFlip(inputImg, outputImg_arm, -1); // run once before timing
  157. gettimeofday(&startTime, NULL);
  158. for (i = 0; i < n; i++)
  159. cvFlip(inputImg, outputImg_arm, -1);
  160. gettimeofday(&endTime, NULL);
  161. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  162. t_avg = (float)t_algo / (float)n;
  163. printf("Called ARM Flip function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  164. // 3.b Apply DSP algorithm
  165. C6accel_cvFlip(hC6accel, inputImg, outputImg_dsp, -1); // run once before timing
  166. gettimeofday(&startTime, NULL);
  167. for (i = 0; i < n; i++)
  168. C6accel_cvFlip(hC6accel, inputImg, outputImg_dsp, -1);
  169. gettimeofday(&endTime, NULL);
  170. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  171. t_avg = (float)t_algo / (float)n;
  172. printf("Called DSP Flip function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  173. // 4.a Copy image on ARM
  174. cvCopy(outputImg_arm, copyImg_arm, NULL); // run once before timing
  175. gettimeofday(&startTime, NULL);
  176. for (i = 0; i < n; i++)
  177. cvCopy(outputImg_arm, copyImg_arm, NULL);
  178. gettimeofday(&endTime, NULL);
  179. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  180. t_avg = (float)t_algo / (float)n;
  181. printf("Called ARM Copy function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  182. // 4.b Copy image on DSP
  183. C6accel_cvCopy(hC6accel, outputImg_dsp, copyImg_dsp, NULL); // run once before timing
  184. gettimeofday(&startTime, NULL);
  185. for (i = 0; i < n; i++)
  186. C6accel_cvCopy(hC6accel, outputImg_dsp, copyImg_dsp, NULL);
  187. gettimeofday(&endTime, NULL);
  188. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  189. t_avg = (float)t_algo / (float)n;
  190. printf("Called DSP Copy function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  191. // 5. Compare outputs
  192. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(copyImg_arm, copyImg_dsp, CV_L2, NULL));
  193. // 6. Save outputs to filesystem
  194. cvSaveImage("./output_arm.png", copyImg_arm, 0);
  195. cvSaveImage("./output_dsp.png", copyImg_dsp, 0);
  196. //OpenCV way of Freeing memory
  197. cvReleaseImage(&outputImg_arm);
  198. cvReleaseImage(&outputImg_dsp);
  199. cvReleaseImage(©Img_arm);
  200. cvReleaseImage(©Img_dsp);
  201. cvReleaseImage(&inputImg);
  202. printf("C6accel_cvFlip test completed successfully; outputs saved to filesystem\n");
  203. return 1;
  204. }
  205. Int c6accel_test_cvCircle(C6accel_Handle hC6accel, char *input_file_name, int n)
  206. {
  207. IplImage *armImg, *dspImg;
  208. struct timeval startTime, endTime;
  209. int t_overhead, t_algo, radius, i;
  210. CvScalar orange = { 0, 128, 255, 255 }, blue = {255, 0, 0, 255}; // BGRA
  211. CvPoint center, pt1, pt2;
  212. float t_avg;
  213. printf("cvCircle Test (%s, %i iterations)\n", input_file_name, n);
  214. // initialize timer
  215. t_overhead = get_overhead_time();
  216. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  217. // 1. Read input image from file
  218. armImg = cvLoadImage( input_file_name, CV_LOAD_IMAGE_COLOR);
  219. dspImg = cvLoadImage( input_file_name, CV_LOAD_IMAGE_COLOR);
  220. // 2. Compute circle and rectangle parameters (center, radius, pt1, pt2)
  221. center.x = armImg->width / 2;
  222. center.y = armImg->height / 2;
  223. radius = (center.x >= center.y) ? center.y : center.x;
  224. pt1.x = pt1.y = 0;
  225. pt2.x = center.x;
  226. pt2.y = armImg->height;
  227. // 3.a Zero out ARM image
  228. cvSetZero(armImg); // run once before timing
  229. gettimeofday(&startTime, NULL);
  230. for (i = 0; i < n; i++)
  231. cvSetZero(armImg);
  232. gettimeofday(&endTime, NULL);
  233. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  234. t_avg = (float)t_algo / (float)n;
  235. printf("Called ARM SetZero function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  236. // 3.b Zero out DSP image
  237. C6accel_cvSetZero(hC6accel, dspImg); // run once before timing
  238. gettimeofday(&startTime, NULL);
  239. for (i = 0; i < n; i++)
  240. C6accel_cvSetZero(hC6accel, dspImg);
  241. gettimeofday(&endTime, NULL);
  242. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  243. t_avg = (float)t_algo / (float)n;
  244. printf("Called DSP SetZero function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  245. // 4.a Draw rectangle on ARM image
  246. cvRectangle(armImg, pt1, pt2, blue, 1, 8, 0); // run once before timing
  247. gettimeofday(&startTime, NULL);
  248. for (i = 0; i < n; i++)
  249. cvRectangle(armImg, pt1, pt2, blue, -1, 8, 0);
  250. gettimeofday(&endTime, NULL);
  251. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  252. t_avg = (float)t_algo / (float)n;
  253. printf("Called ARM Rectangle function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  254. // 4.b Draw rectangle on DSP image
  255. C6accel_cvRectangle(hC6accel, dspImg, pt1, pt2, blue, 1, 8, 0); // run once before timing
  256. gettimeofday(&startTime, NULL);
  257. for (i = 0; i < n; i++)
  258. C6accel_cvRectangle(hC6accel, dspImg, pt1, pt2, blue, -1, 8, 0);
  259. gettimeofday(&endTime, NULL);
  260. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  261. t_avg = (float)t_algo / (float)n;
  262. printf("Called DSP Rectangle function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  263. // 5.a Draw circle on ARM image
  264. cvCircle(armImg, center, radius, orange, 1, 8, 0); // run once before timing
  265. gettimeofday(&startTime, NULL);
  266. for (i = 0; i < n; i++)
  267. cvCircle(armImg, center, radius, orange, -1, 8, 0);
  268. gettimeofday(&endTime, NULL);
  269. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  270. t_avg = (float)t_algo / (float)n;
  271. printf("Called ARM Circle function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  272. // 5.b Draw circle on DSP image
  273. C6accel_cvCircle(hC6accel, dspImg, center, radius, orange, 1, 8, 0); // run once before timing
  274. gettimeofday(&startTime, NULL);
  275. for (i = 0; i < n; i++)
  276. C6accel_cvCircle(hC6accel, dspImg, center, radius, orange, -1, 8, 0);
  277. gettimeofday(&endTime, NULL);
  278. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  279. t_avg = (float)t_algo / (float)n;
  280. printf("Called DSP Circle function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  281. // 6. Compare outputs
  282. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(armImg, dspImg, CV_L2, NULL));
  283. // 7. Save outputs to filesystem
  284. cvSaveImage("./output_arm.png", armImg, 0);
  285. cvSaveImage("./output_dsp.png", dspImg, 0);
  286. // Free memory
  287. cvReleaseImage(&armImg);
  288. cvReleaseImage(&dspImg);
  289. printf("C6accel_cvCircle test completed successfully; outputs saved to filesystem\n");
  290. return 1;
  291. }
  292. Int c6accel_test_cvResize(C6accel_Handle hC6accel, char *input_file_name, int n)
  293. {
  294. IplImage *inputImg, *colorImg_arm, *colorImg_dsp, *resizeImg_arm, *resizeImg_dsp;
  295. struct timeval startTime, endTime;
  296. int t_overhead, t_algo, i;
  297. float t_avg;
  298. printf("cvResize Test (%s, %i iterations)\n", input_file_name, n);
  299. // initialize timer
  300. t_overhead = get_overhead_time();
  301. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  302. // 1. Read input image from file
  303. inputImg = cvLoadImage( input_file_name, CV_LOAD_IMAGE_COLOR);
  304. // 2. Allocate recolor images (must same depth, channels, size as input)
  305. // and resize images (must have same depth, channels, as input with half size)
  306. colorImg_arm = cvCreateImage(cvSize(inputImg->width, inputImg->height), inputImg->depth, inputImg->nChannels);
  307. colorImg_dsp = cvCreateImage(cvSize(inputImg->width, inputImg->height), inputImg->depth, inputImg->nChannels);
  308. resizeImg_arm = cvCreateImage(cvSize(inputImg->width / 2, inputImg->height / 2), inputImg->depth, inputImg->nChannels);
  309. resizeImg_dsp = cvCreateImage(cvSize(inputImg->width / 2, inputImg->height / 2), inputImg->depth, inputImg->nChannels);
  310. // 3.a Apply ARM algorithm
  311. cvCvtColor(inputImg, colorImg_arm, CV_BGR2YCrCb); // run once before timing
  312. gettimeofday(&startTime, NULL);
  313. for (i = 0; i < n; i++)
  314. cvCvtColor(inputImg, colorImg_arm, CV_BGR2YCrCb);
  315. gettimeofday(&endTime, NULL);
  316. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  317. t_avg = (float)t_algo / (float)n;
  318. printf("Called ARM CvtColor function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  319. // 3.b Apply DSP algorithm
  320. C6accel_cvCvtColor(hC6accel, inputImg, colorImg_dsp, CV_BGR2YCrCb); // run once before timing
  321. gettimeofday(&startTime, NULL);
  322. //for (i = 0; i < 1000; i++)
  323. C6accel_cvCvtColor(hC6accel, inputImg, colorImg_dsp, CV_BGR2YCrCb);
  324. gettimeofday(&endTime, NULL);
  325. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  326. t_avg = (float)t_algo / (float)n;
  327. printf("Called DSP CvtColor function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  328. // 4.a Resize image on ARM
  329. cvResize(colorImg_arm, resizeImg_arm, CV_INTER_LINEAR); // run once before timing
  330. gettimeofday(&startTime, NULL);
  331. for (i = 0; i < n; i++)
  332. cvResize(colorImg_arm, resizeImg_arm, CV_INTER_LINEAR);
  333. gettimeofday(&endTime, NULL);
  334. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  335. t_avg = (float)t_algo / (float)n;
  336. printf("Called ARM Resize function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  337. // 4.b Resize image on DSP
  338. C6accel_cvResize(hC6accel, colorImg_dsp, resizeImg_dsp, CV_INTER_LINEAR); // run once before timing
  339. gettimeofday(&startTime, NULL);
  340. for (i = 0; i < n; i++)
  341. C6accel_cvResize(hC6accel, colorImg_dsp, resizeImg_dsp, CV_INTER_LINEAR);
  342. gettimeofday(&endTime, NULL);
  343. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  344. t_avg = (float)t_algo / (float)n;
  345. printf("Called DSP Resize function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  346. // 5. Compare outputs
  347. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(resizeImg_arm, resizeImg_dsp, CV_L2, NULL));
  348. // 6. Save outputs to filesystem
  349. cvSaveImage("./output_arm.png", resizeImg_arm, 0);
  350. cvSaveImage("./output_dsp.png", resizeImg_dsp, 0);
  351. // Free memory
  352. cvReleaseImage(&resizeImg_arm);
  353. cvReleaseImage(&resizeImg_dsp);
  354. cvReleaseImage(&colorImg_arm);
  355. cvReleaseImage(&colorImg_dsp);
  356. cvReleaseImage(&inputImg);
  357. printf("C6accel_cvResize test completed successfully; outputs saved to filesystem\n");
  358. return 1;
  359. }
  360. Int c6accel_test_cvEqualizeHist(C6accel_Handle hC6accel, char *input_file_name, int n)
  361. {
  362. IplImage *inputImg, *outputImg_arm, *outputImg_dsp;
  363. struct timeval startTime, endTime;
  364. int t_overhead, t_algo, i;
  365. float t_avg;
  366. printf("cvEqualizeHist Test (%s, %i iterations)\n", input_file_name, n);
  367. // initialize timer
  368. t_overhead = get_overhead_time();
  369. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  370. // 1. Read input image from file
  371. inputImg = cvLoadImage( input_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  372. // 2. Check image depth; require 8-bit
  373. if (inputImg->depth != IPL_DEPTH_8U && inputImg->depth != IPL_DEPTH_8S)
  374. {
  375. printf("C6accel_cvEqualizeHist test failed; input image must have 8-bit depth.\n");
  376. return 0;
  377. }
  378. // 3. Allocate output images
  379. outputImg_arm = cvCreateImage(cvSize(inputImg->width, inputImg->height), IPL_DEPTH_8U, 1);
  380. outputImg_dsp = cvCreateImage(cvSize(inputImg->width, inputImg->height), IPL_DEPTH_8U, 1);
  381. // 4.a Apply ARM algorithm
  382. cvEqualizeHist(inputImg, outputImg_arm); // run once before timing
  383. gettimeofday(&startTime, NULL);
  384. for (i = 0; i < n; i++)
  385. cvEqualizeHist(inputImg, outputImg_arm);
  386. gettimeofday(&endTime, NULL);
  387. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  388. t_avg = (float)t_algo / (float)n;
  389. printf("Called ARM EqualizeHist function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  390. // 4.b Apply DSP algorithm
  391. C6accel_cvEqualizeHist(hC6accel, inputImg, outputImg_dsp); // run once before timing
  392. gettimeofday(&startTime, NULL);
  393. for (i = 0; i < n; i++)
  394. C6accel_cvEqualizeHist(hC6accel, inputImg, outputImg_dsp);
  395. gettimeofday(&endTime, NULL);
  396. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  397. t_avg = (float)t_algo / (float)n;
  398. printf("Called DSP EqualizeHist function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  399. // 6. Compare outputs
  400. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  401. // 7. Save outputs to filesystem
  402. cvSaveImage("./output_arm.png", outputImg_arm, 0);
  403. cvSaveImage("./output_dsp.png", outputImg_dsp, 0);
  404. // Free memory
  405. cvReleaseImage(&outputImg_arm);
  406. cvReleaseImage(&outputImg_dsp);
  407. cvReleaseImage(&inputImg);
  408. printf("C6accel_cvEqualizeHist test completed successfully; outputs saved to filesystem\n");
  409. return 1;
  410. }
  411. // TEMP: function to traverse classifier cascade
  412. typedef int sumtype;
  413. typedef double sqsumtype;
  414. typedef struct CvHidHaarFeature
  415. {
  416. struct
  417. {
  418. sumtype *p0, *p1, *p2, *p3;
  419. float weight;
  420. }
  421. rect[CV_HAAR_FEATURE_MAX];
  422. }
  423. CvHidHaarFeature;
  424. typedef struct CvHidHaarTreeNode
  425. {
  426. CvHidHaarFeature feature;
  427. float threshold;
  428. int left;
  429. int right;
  430. }
  431. CvHidHaarTreeNode;
  432. typedef struct CvHidHaarClassifier
  433. {
  434. int count;
  435. //CvHaarFeature* orig_feature;
  436. CvHidHaarTreeNode* node;
  437. float* alpha;
  438. }
  439. CvHidHaarClassifier;
  440. typedef struct CvHidHaarStageClassifier
  441. {
  442. int count;
  443. float threshold;
  444. CvHidHaarClassifier* classifier;
  445. int two_rects;
  446. struct CvHidHaarStageClassifier* next;
  447. struct CvHidHaarStageClassifier* child;
  448. struct CvHidHaarStageClassifier* parent;
  449. }
  450. CvHidHaarStageClassifier;
  451. struct CvHidHaarClassifierCascade
  452. {
  453. int count;
  454. int is_stump_based;
  455. int has_tilted_features;
  456. int is_tree;
  457. double inv_window_area;
  458. CvMat sum, sqsum, tilted;
  459. CvHidHaarStageClassifier* stage_classifier;
  460. sqsumtype *pq0, *pq1, *pq2, *pq3;
  461. sumtype *p0, *p1, *p2, *p3;
  462. void** ipp_stages;
  463. };
  464. void traverse_and_translate_hid_cascade(CvHidHaarClassifierCascade *cascade, FILE *fp)
  465. {
  466. CvHidHaarStageClassifier *hid_stage;
  467. CvHidHaarClassifier *hid_classifier;
  468. CvHidHaarTreeNode *hid_node;
  469. int stage_count, classifier_count, feature_count;
  470. int i, j, k, l;
  471. if (cascade == NULL)
  472. {
  473. fprintf(fp, "//\tHidden cascade pointer is NULL; no traversal required\n");
  474. return;
  475. }
  476. else
  477. {
  478. stage_count = cascade->count;
  479. fprintf(fp, "//\tHidden cascade at 0x%08X has %i stages\n",
  480. (unsigned int)cascade,
  481. stage_count);
  482. for (i = 0; i < cascade->count; i++)
  483. {
  484. hid_stage = cascade->stage_classifier + i;
  485. classifier_count = hid_stage->count;
  486. fprintf(fp, "//\t\tHidden stage %i at 0x%08X has %i classifiers\n",
  487. i, (unsigned int)hid_stage, classifier_count);
  488. for (j = 0; j < classifier_count; j++)
  489. {
  490. hid_classifier = hid_stage->classifier + j;
  491. feature_count = hid_classifier->count;
  492. fprintf(fp, "//\t\t\tHidden classifier %i at 0x%08X has %i nodes/features\n",
  493. j, (unsigned int)hid_classifier, feature_count);
  494. for (k = 0; k < feature_count; k++)
  495. {
  496. hid_node = hid_classifier->node + k;
  497. // apply CMEM_getPhys to node contents (none)
  498. // apply CMEM_getPhys to feature contents (rect[0].p0, .p1, .p2, .p3, rect[1].p0, etc.)
  499. for (l = 0; l < CV_HAAR_FEATURE_MAX; l++)
  500. {
  501. hid_node->feature.rect[l].p0 = hid_node->feature.rect[l].p0 ?
  502. (void *)CMEM_getPhys(hid_node->feature.rect[l].p0) : NULL;
  503. hid_node->feature.rect[l].p1 = hid_node->feature.rect[l].p1 ?
  504. (void *)CMEM_getPhys(hid_node->feature.rect[l].p1) : NULL;
  505. hid_node->feature.rect[l].p2 = hid_node->feature.rect[l].p2 ?
  506. (void *)CMEM_getPhys(hid_node->feature.rect[l].p2) : NULL;
  507. hid_node->feature.rect[l].p3 = hid_node->feature.rect[l].p3 ?
  508. (void *)CMEM_getPhys(hid_node->feature.rect[l].p3) : NULL;
  509. fprintf(fp, "//\t\t\t\tHidden node %i feature rect %i pointers translated to physical addresses (0x%08X, 0x%08X, 0x%08X, 0x%08X)\n",
  510. k, l, (unsigned int)hid_node->feature.rect[l].p0, (unsigned int)hid_node->feature.rect[l].p1,
  511. hid_node->feature.rect[l].p2, hid_node->feature.rect[l].p3);
  512. }
  513. }
  514. // apply CMEM_getPhys to classifier contents (node, alpha)
  515. hid_classifier->node = hid_classifier->node ? (void *)CMEM_getPhys(hid_classifier->node) : NULL;
  516. hid_classifier->alpha = hid_classifier->alpha ? (void *)CMEM_getPhys(hid_classifier->alpha) : NULL;
  517. fprintf(fp, "//\t\t\tHidden classifier %i pointers translated to physical addresses (0x%08X, 0x%08X)\n",
  518. j, (unsigned int)hid_classifier->node, (unsigned int)hid_classifier->alpha);
  519. }
  520. // apply CMEM_getPhys to stage contents (classifier, next, child, parent)
  521. hid_stage->classifier = hid_stage->classifier ? (void *)CMEM_getPhys(hid_stage->classifier) : NULL;
  522. hid_stage->next = hid_stage->next ? (void *)CMEM_getPhys(hid_stage->next) : NULL;
  523. hid_stage->child = hid_stage->child ? (void *)CMEM_getPhys(hid_stage->child) : NULL;
  524. hid_stage->parent = hid_stage->parent ? (void *)CMEM_getPhys(hid_stage->parent) : NULL;
  525. fprintf(fp, "//\t\tHidden stage %i pointers translated to physical addresses (0x%08X, 0x%08X, 0x%08X, 0x%08X)\n",
  526. i, (unsigned int)hid_stage->classifier, (unsigned int)hid_stage->next,
  527. (unsigned int)hid_stage->child, (unsigned int)hid_stage->parent);
  528. }
  529. // apply CMEM_getPhys to hid_cascade contents (stage_classifier, sum.refcount, sum.data.i,
  530. // sqsum.refcount, sqsum.data.db, tilted.refcount, tilted.data.i, pq0, pq1, pq2, pq3,
  531. // p0, p1, p2, p3, ipp_stages)
  532. cascade->stage_classifier = cascade->stage_classifier ?
  533. (void *)CMEM_getPhys(cascade->stage_classifier) : NULL;
  534. cascade->sum.refcount = cascade->sum.refcount ?
  535. (void *)CMEM_getPhys(cascade->sum.refcount) : NULL;
  536. cascade->sum.data.i = cascade->sum.data.i ?
  537. (void *)CMEM_getPhys(cascade->sum.data.i) : NULL;
  538. cascade->sqsum.refcount = cascade->sqsum.refcount ?
  539. (void *)CMEM_getPhys(cascade->sqsum.refcount) : NULL;
  540. cascade->sqsum.data.db = cascade->sqsum.data.db ?
  541. (void *)CMEM_getPhys(cascade->sqsum.data.db) : NULL;
  542. cascade->tilted.refcount = cascade->tilted.refcount ?
  543. (void *)CMEM_getPhys(cascade->tilted.refcount) : NULL;
  544. cascade->tilted.data.i = cascade->tilted.data.i ?
  545. (void *)CMEM_getPhys(cascade->tilted.data.i) : NULL;
  546. fprintf(fp, "//\tHidden cascade pointers translated to physical addresses (1 of 4) (0x%08X, 0x%08X, 0x%08X)\n",
  547. (unsigned int)cascade->stage_classifier, (unsigned int)cascade->sum.refcount,
  548. (unsigned int)cascade->sum.data.i);
  549. fprintf(fp, "//\tHidden cascade pointers translated to physical addresses (2 of 4) (0x%08X, 0x%08X, 0x%08X, 0x%08X)\n",
  550. (unsigned int)cascade->sqsum.refcount, (unsigned int)cascade->sqsum.data.db,
  551. (unsigned int)cascade->tilted.refcount, (unsigned int)cascade->tilted.data.i);
  552. cascade->pq0 = cascade->pq0 ? (void *)CMEM_getPhys(cascade->pq0) : NULL;
  553. cascade->pq1 = cascade->pq1 ? (void *)CMEM_getPhys(cascade->pq1) : NULL;
  554. cascade->pq2 = cascade->pq2 ? (void *)CMEM_getPhys(cascade->pq2) : NULL;
  555. cascade->pq3 = cascade->pq3 ? (void *)CMEM_getPhys(cascade->pq3) : NULL;
  556. cascade->p0 = cascade->p0 ? (void *)CMEM_getPhys(cascade->p0) : NULL;
  557. cascade->p1 = cascade->p1 ? (void *)CMEM_getPhys(cascade->p1) : NULL;
  558. cascade->p2 = cascade->p2 ? (void *)CMEM_getPhys(cascade->p2) : NULL;
  559. cascade->p3 = cascade->p3 ? (void *)CMEM_getPhys(cascade->p3) : NULL;
  560. fprintf(fp, "//\tHidden cascade pointers translated to physical addresses (3 of 4) (0x%08X, 0x%08X, 0x%08X, 0x%08X)\n",
  561. (unsigned int)cascade->pq0, (unsigned int)cascade->pq1,
  562. (unsigned int)cascade->pq2, (unsigned int)cascade->pq3);
  563. fprintf(fp, "//\tHidden cascade pointers translated to physical addresses (4 of 4) (0x%08X, 0x%08X, 0x%08X, 0x%08X)\n",
  564. (unsigned int)cascade->p0, (unsigned int)cascade->p1,
  565. (unsigned int)cascade->p2, (unsigned int)cascade->p3);
  566. if (cascade->ipp_stages == NULL)
  567. {
  568. fprintf(fp, "//\tHidden cascade ipp stage array pointer is NULL; sub-array not traversed\n");
  569. }
  570. else
  571. {
  572. for (i = 0; i < cascade->count; i++)
  573. {
  574. cascade->ipp_stages[i] = cascade->ipp_stages[i] ?
  575. (void *)CMEM_getPhys(cascade->ipp_stages[i]) : NULL;
  576. fprintf(fp, "//\tHidden cascade ipp stage %i translated to physical address (0x%08X)\n",
  577. i, (unsigned int)cascade->ipp_stages[i]);
  578. }
  579. }
  580. cascade->ipp_stages = cascade->ipp_stages ?
  581. (void *)CMEM_getPhys(cascade->ipp_stages) : NULL;
  582. fprintf(fp, "//\tHidden cascade ipp stage array pointer translated to physical address (0x%08X)\n",
  583. (unsigned int)cascade->ipp_stages);
  584. }
  585. }
  586. void LOCAL_restore_hid_cascade(CvHidHaarClassifierCascade *cascade)
  587. {
  588. CvHidHaarStageClassifier *hid_stage;
  589. CvHidHaarClassifier *hid_classifier;
  590. CvHidHaarTreeNode *hid_node;
  591. int stage_count, classifier_count, feature_count;
  592. int i, j, k, l;
  593. if (cascade == NULL)
  594. {
  595. return;
  596. }
  597. else
  598. {
  599. stage_count = cascade->count;
  600. // apply Memory_getBufferVirtualAddress to hid_cascade contents (stage_classifier, sum.refcount, sum.data.i,
  601. // sqsum.refcount, sqsum.data.db, tilted.refcount, tilted.data.i, pq0, pq1, pq2, pq3,
  602. // p0, p1, p2, p3, ipp_stages)
  603. cascade->stage_classifier = cascade->stage_classifier ?
  604. (void *)Memory_getBufferVirtualAddress((int)cascade->stage_classifier,sizeof(CvHidHaarStageClassifier)) : NULL;
  605. cascade->sum.refcount = cascade->sum.refcount ?
  606. (void *)Memory_getBufferVirtualAddress((int)cascade->sum.refcount,sizeof(int)) : NULL;
  607. cascade->sum.data.i = cascade->sum.data.i ?
  608. (void *)Memory_getBufferVirtualAddress((int)cascade->sum.data.i,sizeof(int)) : NULL;
  609. cascade->sqsum.refcount = cascade->sqsum.refcount ?
  610. (void *)Memory_getBufferVirtualAddress((int)cascade->sqsum.refcount,sizeof(int)) : NULL;
  611. cascade->sqsum.data.db = cascade->sqsum.data.db ?
  612. (void *)Memory_getBufferVirtualAddress((int)cascade->sqsum.data.db,sizeof(double *)) : NULL;
  613. cascade->tilted.refcount = cascade->tilted.refcount ?
  614. (void *)Memory_getBufferVirtualAddress((int)cascade->tilted.refcount,sizeof(int)) : NULL;
  615. cascade->tilted.data.i = cascade->tilted.data.i ?
  616. (void *)Memory_getBufferVirtualAddress((int)cascade->tilted.data.i,sizeof(int)) : NULL;
  617. cascade->pq0 = cascade->pq0 ? (void *)Memory_getBufferVirtualAddress((int)cascade->pq0,sizeof(sqsumtype)) : NULL;
  618. cascade->pq1 = cascade->pq1 ? (void *)Memory_getBufferVirtualAddress((int)cascade->pq1,sizeof(sqsumtype)) : NULL;
  619. cascade->pq2 = cascade->pq2 ? (void *)Memory_getBufferVirtualAddress((int)cascade->pq2,sizeof(sqsumtype)) : NULL;
  620. cascade->pq3 = cascade->pq3 ? (void *)Memory_getBufferVirtualAddress((int)cascade->pq3,sizeof(sqsumtype)) : NULL;
  621. cascade->p0 = cascade->p0 ? (void *)Memory_getBufferVirtualAddress((int)cascade->p0,sizeof(sumtype)) : NULL;
  622. cascade->p1 = cascade->p1 ? (void *)Memory_getBufferVirtualAddress((int)cascade->p1,sizeof(sumtype)) : NULL;
  623. cascade->p2 = cascade->p2 ? (void *)Memory_getBufferVirtualAddress((int)cascade->p2,sizeof(sumtype)) : NULL;
  624. cascade->p3 = cascade->p3 ? (void *)Memory_getBufferVirtualAddress((int)cascade->p3,sizeof(sumtype)) : NULL;
  625. for (i = 0; i < cascade->count; i++)
  626. {
  627. hid_stage = cascade->stage_classifier + i;
  628. classifier_count = hid_stage->count;
  629. // apply Memory_getBufferVirtualAddress to stage contents (classifier, next, child, parent)
  630. hid_stage->classifier = hid_stage->classifier ? (void *)Memory_getBufferVirtualAddress((int)hid_stage->classifier,sizeof(CvHidHaarClassifier)) : NULL;
  631. hid_stage->next = hid_stage->next ? (void *)Memory_getBufferVirtualAddress((int)hid_stage->next,sizeof(CvHidHaarStageClassifier)) : NULL;
  632. hid_stage->child = hid_stage->child ? (void *)Memory_getBufferVirtualAddress((int)hid_stage->child,sizeof(CvHidHaarStageClassifier)) : NULL;
  633. hid_stage->parent = hid_stage->parent ? (void *)Memory_getBufferVirtualAddress((int)hid_stage->parent,sizeof(CvHidHaarStageClassifier)) : NULL;
  634. for (j = 0; j < classifier_count; j++)
  635. {
  636. hid_classifier = hid_stage->classifier + j;
  637. feature_count = hid_classifier->count;
  638. // apply Memory_getBufferVirtualAddress to classifier contents (node, alpha)
  639. hid_classifier->node = hid_classifier->node ? (void *)Memory_getBufferVirtualAddress((int)hid_classifier->node,sizeof(CvHidHaarTreeNode)) : NULL;
  640. hid_classifier->alpha = hid_classifier->alpha ? (void *)Memory_getBufferVirtualAddress((int)hid_classifier->alpha,sizeof(float)) : NULL;
  641. for (k = 0; k < feature_count; k++)
  642. {
  643. hid_node = hid_classifier->node + k;
  644. // apply Memory_getBufferVirtualAddress to node contents (none)
  645. // apply Memory_getBufferVirtualAddress to feature contents (rect[0].p0, .p1, .p2, .p3, rect[1].p0, etc.)
  646. for (l = 0; l < CV_HAAR_FEATURE_MAX; l++)
  647. {
  648. hid_node->feature.rect[l].p0 = hid_node->feature.rect[l].p0 ?
  649. (void *)Memory_getBufferVirtualAddress((int)hid_node->feature.rect[l].p0,sizeof(sumtype)) : NULL;
  650. hid_node->feature.rect[l].p1 = hid_node->feature.rect[l].p1 ?
  651. (void *)Memory_getBufferVirtualAddress((int)hid_node->feature.rect[l].p1,sizeof(sumtype)) : NULL;
  652. hid_node->feature.rect[l].p2 = hid_node->feature.rect[l].p2 ?
  653. (void *)Memory_getBufferVirtualAddress((int)hid_node->feature.rect[l].p2,sizeof(sumtype)) : NULL;
  654. hid_node->feature.rect[l].p3 = hid_node->feature.rect[l].p3 ?
  655. (void *)Memory_getBufferVirtualAddress((int)hid_node->feature.rect[l].p3,sizeof(sumtype)) : NULL;
  656. }
  657. }
  658. }
  659. }
  660. if (cascade->ipp_stages == NULL)
  661. {
  662. printf( "//\tHidden cascade ipp stage array pointer is NULL; sub-array not traversed\n");
  663. }
  664. else
  665. {
  666. for (i = 0; i < cascade->count; i++)
  667. {
  668. cascade->ipp_stages[i] = cascade->ipp_stages[i] ?
  669. (void *)Memory_getBufferVirtualAddress((int)cascade->ipp_stages[i],sizeof(void *)) : NULL;
  670. }
  671. }
  672. cascade->ipp_stages = cascade->ipp_stages ?
  673. (void *)Memory_getBufferVirtualAddress((int)cascade->ipp_stages,sizeof(void *)) : NULL;
  674. }
  675. }
  676. void traverse_and_translate_cascade(CvHaarClassifierCascade *cascade )
  677. {
  678. CvHaarStageClassifier *stage;
  679. CvHaarClassifier *classifier;
  680. CvHaarFeature *feature;
  681. int stage_count, classifier_count, feature_count;
  682. unsigned int new_thresh, new_left, new_right, new_alpha;
  683. int i, j, k;
  684. FILE *fp = fopen("dsp_cascade_traversal_log.txt", "w+");
  685. stage_count = cascade->count;
  686. fprintf(fp, "Cascade at 0x%08X has %i stages\n",
  687. (unsigned int)cascade,
  688. stage_count);
  689. for (i = 0; i < stage_count; i++)
  690. {
  691. stage = cascade->stage_classifier + i;
  692. classifier_count = stage->count;
  693. fprintf(fp, "\tStage %i at 0x%08X has %i classifiers\n", i, (unsigned int)stage, classifier_count);
  694. for (j = 0; j < classifier_count; j++)
  695. {
  696. classifier = stage->classifier + j;
  697. feature_count = classifier->count;
  698. fprintf(fp, "\t\tClassifier %i at 0x%08X has %i features\n", j, (unsigned int)classifier, feature_count);
  699. for (k = 0; k < feature_count; k++)
  700. {
  701. feature = classifier->haar_feature + k;
  702. fprintf(fp, "\t\t\tFeature %i at 0x%08X rect array that begins at 0x%08X\n", k,
  703. (unsigned int)feature, (unsigned int)feature->rect);
  704. // apply CMEM_getPhys to feature contents (rect)
  705. // NOT NECESSARY (array pointer doesn't actually exist; feature->rect == (char *)feature + 4
  706. //feature->rect = (unsigned int)CMEM_getPhys(feature->rect);
  707. //fprintf(fp, "0x%08X\n", (unsigned int)feature->rect);
  708. }
  709. // apply CMEM_getPhys to classifier contents (haar_feature, threshold, left, right, alpha)
  710. classifier->haar_feature = classifier->haar_feature ? (void *)Memory_getBufferPhysicalAddress(classifier->haar_feature, sizeof(CvHaarFeature),NULL) : NULL;
  711. classifier->threshold = classifier->threshold ? (void *)Memory_getBufferPhysicalAddress(classifier->threshold,sizeof(float),NULL) : NULL;
  712. classifier->left = classifier->left ? (void *)Memory_getBufferPhysicalAddress(classifier->left,sizeof(int),NULL) : NULL;
  713. classifier->right = classifier->right ? (void *)Memory_getBufferPhysicalAddress(classifier->right,sizeof(int),NULL) : NULL;
  714. classifier->alpha = classifier->alpha ? (void *)Memory_getBufferPhysicalAddress(classifier->alpha,sizeof(float),NULL) : NULL;
  715. fprintf(fp, "\t\tClassifier %i pointers translated to physical addresses (0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X)\n",
  716. j, (unsigned int)classifier->haar_feature, (unsigned int)classifier->threshold,
  717. (unsigned int)classifier->left, (unsigned int)classifier->right,
  718. (unsigned int)classifier->alpha);
  719. Memory_cacheWbInv( (void *)classifier, sizeof(CvHaarClassifier));
  720. // Cache_wait();
  721. }
  722. // apply CMEM_getPhys to stage contents (classifier)
  723. fprintf(fp, "\tBefore translation :Stage %i pointers translated to physical addresses (0x%08X)\n", i, (unsigned int)stage->classifier);
  724. stage->classifier = stage->classifier ? (void *)Memory_getBufferPhysicalAddress(stage->classifier,sizeof(CvHaarClassifier),NULL) : NULL;
  725. Memory_cacheWbInv( (void *)stage,sizeof(CvHaarStageClassifier));
  726. fprintf(fp, "\tStage %i pointers translated to physical addresses (0x%08X)\n", i, (unsigned int)stage->classifier);
  727. }
  728. // traverse "hidden" cascade, too
  729. traverse_and_translate_hid_cascade(cascade->hid_cascade, fp);
  730. // apply CMEM_getPhys to cascade contents (stage_classifier, hid_cascade)
  731. // cascade->stage_classifier->classifier = cascade->stage_classifier->classifier ? (void *)CMEM_getPhys(cascade->stage_classifier->classifier) : NULL;
  732. cascade->stage_classifier = cascade->stage_classifier ? (void *)Memory_getBufferPhysicalAddress(cascade->stage_classifier,sizeof(CvHaarStageClassifier),NULL) : NULL;
  733. cascade->hid_cascade = cascade->hid_cascade ? (void *)Memory_getBufferPhysicalAddress(cascade->hid_cascade,sizeof(CvHidHaarClassifierCascade),NULL) : NULL;
  734. fprintf(fp, "Cascade pointers translated to physical addresses (0x%08X, 0x%08X)\n", (unsigned int)cascade->stage_classifier,
  735. (unsigned int)cascade->hid_cascade);
  736. Memory_cacheWbInvAll();
  737. //Cache_wait();
  738. fclose(fp);
  739. }
  740. void LOCAL_restore_cascade(CvHaarClassifierCascade *cascade)
  741. {
  742. CvHaarStageClassifier *stage;
  743. CvHaarClassifier *classifier;
  744. CvHaarFeature *feature;
  745. int stage_count, classifier_count, feature_count;
  746. unsigned int new_thresh, new_left, new_right, new_alpha;
  747. int i, j, k;
  748. stage_count = cascade->count;
  749. // printf("Stage_classifier %x\n",(int)cascade->stage_classifier);
  750. cascade->stage_classifier = (void *)Memory_getBufferVirtualAddress(((int)cascade->stage_classifier),sizeof(CvHaarStageClassifier)+sizeof(int));
  751. // printf("Stage_classifier %x\n",(int)cascade->stage_classifier);
  752. cascade->hid_cascade = cascade->hid_cascade ? (void *)Memory_getBufferVirtualAddress((int)cascade->hid_cascade,sizeof(CvHidHaarClassifierCascade)): NULL;
  753. for (i = 0; i < stage_count; i++)
  754. {
  755. // printf("In stage loop\n");
  756. stage = cascade->stage_classifier + i;
  757. // printf("stage %x\n",(int)stage );
  758. classifier_count = stage->count;
  759. // apply CMEM_getPhys to stage contents (classifier)
  760. stage->classifier = (void *)Memory_getBufferVirtualAddress((int)stage->classifier,sizeof(CvHaarClassifier));
  761. for (j = 0; j < classifier_count; j++)
  762. {
  763. // printf("In classifier loop\n");
  764. classifier = stage->classifier + j;
  765. // printf(" classifier %x\n", classifier);
  766. feature_count = classifier->count;
  767. // apply CMEM_getPhys to classifier contents (haar_feature, threshold, left, right, alpha)
  768. classifier->haar_feature = (void *)Memory_getBufferVirtualAddress((int)(classifier->haar_feature),sizeof(CvHaarFeature));
  769. classifier->threshold = (void *)Memory_getBufferVirtualAddress((int)classifier->threshold,sizeof(float)) ;
  770. classifier->left = (void *)Memory_getBufferVirtualAddress((int)classifier->left,sizeof(int));
  771. classifier->right = (void *)Memory_getBufferVirtualAddress((int)classifier->right,sizeof(int));
  772. classifier->alpha = (void *)Memory_getBufferVirtualAddress((int)classifier->alpha,sizeof(float));
  773. // Memory_cacheWbInv( (void *)classifier, sizeof(CvHaarClassifier));
  774. for (k = 0; k < feature_count; k++)
  775. {
  776. // printf("In Feature loop\n");
  777. feature = classifier->haar_feature + k;
  778. // apply CMEM_getPhys to feature contents (rect)
  779. // NOT NECESSARY (array pointer doesn't actually exist; feature->rect == (char *)feature + 4
  780. //feature->rect = (unsigned int)CMEM_getPhys(feature->rect);
  781. //fprintf(fp, "0x%08X\n", (unsigned int)feature->rect);
  782. }
  783. }
  784. }
  785. LOCAL_restore_hid_cascade(cascade->hid_cascade);
  786. }
  787. Int c6accel_test_cvHaarDetectObjects(C6accel_Handle hC6accel, char *image_file_name, char *cascade_file_name)
  788. {
  789. IplImage *image, *image_color;
  790. CvSeq *arm_sequence = NULL, *dsp_sequence = NULL;
  791. CvHaarClassifierCascade *cascade;
  792. CvMemStorage *storage;
  793. CvRect *r;
  794. CvPoint c1, c2;
  795. CvScalar red = {0, 0, 255, 255}, black = {0, 0, 0, 255};
  796. struct timeval startTime, endTime;
  797. int t_overhead, t_algo, i;
  798. void *temp_ptr;
  799. printf("cvHaarDetectObjects Test (%s, %s)\n", image_file_name, cascade_file_name);
  800. // initialize timer
  801. t_overhead = get_overhead_time();
  802. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  803. printf("Memory for images,cascade and \n");
  804. // 1. Read input image and cascade files
  805. image = cvLoadImage(image_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  806. image_color = cvLoadImage(image_file_name, CV_LOAD_IMAGE_COLOR);
  807. // 2. Create memory storage space; use dummy allocation to prime for DSP
  808. storage = cvCreateMemStorage(0);
  809. printf("Memory allocation for images and storage done\n");
  810. cascade = (CvHaarClassifierCascade *)cvLoad(cascade_file_name, 0, 0, 0);
  811. printf("Reading of Cascade complete\n");
  812. // 3.a Apply ARM algorithm
  813. arm_sequence = cvHaarDetectObjects(image_color, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(30, 30));
  814. gettimeofday(&startTime, NULL);
  815. printf("top= %x\n", storage->top);
  816. printf("bottom= %x\n", storage->bottom);
  817. for (i = 0; i < 1; i++)
  818. arm_sequence = cvHaarDetectObjects(image_color, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(30, 30));
  819. gettimeofday(&endTime, NULL);
  820. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  821. printf("Called ARM HaarDetectObjects function (time: %f ms)\n", t_algo / 1000.0 / 1.0);
  822. // 4.a Mark and print list of matches detected by ARM
  823. if (arm_sequence == NULL)
  824. {
  825. printf("ARM sequence returned NULL\n");
  826. }
  827. else
  828. {
  829. printf("ARM sequence contains %i elements:\n", arm_sequence->total);
  830. for (i = 0; i < arm_sequence->total; i++){
  831. r = (CvRect *)cvGetSeqElem(arm_sequence, i);
  832. printf("%4i: %4i, %4i (%ix%i)\n", i, r->x, r->y, r->width, r->height);
  833. // mark with thick black rectangle
  834. c1.x = r->x;
  835. c1.y = r->y;
  836. c2.x = r->x + r->width;
  837. c2.y = r->y + r->height;
  838. cvRectangle(image_color, c1, c2, black, 2, 8, 0);
  839. }
  840. }
  841. cvReleaseHaarClassifierCascade(&cascade);
  842. cvReleaseMemStorage(&storage);
  843. // 3.b Apply DSP algorithm
  844. storage = cvCreateMemStorage(0);
  845. temp_ptr = cvMemStorageAlloc(storage, 64);
  846. printf("Memory allocation for images and storage done\n");
  847. cascade = (CvHaarClassifierCascade *)cvLoad(cascade_file_name, 0, 0, 0);
  848. traverse_and_translate_cascade(cascade);
  849. gettimeofday(&startTime, NULL);
  850. C6accel_cvHaarDetectObjects(hC6accel, image_color, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(30, 30), &dsp_sequence);
  851. gettimeofday(&endTime, NULL);
  852. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  853. printf("Called DSP HaarDetectObjects function (time: %f ms)\n", t_algo / 1000.0);
  854. // 4.b Mark and print list of matches detected by DSP
  855. if (dsp_sequence == NULL)
  856. {
  857. printf("DSP sequence returned NULL\n");
  858. }
  859. else
  860. {
  861. printf("DSP sequence contains %i elements:\n", dsp_sequence->total);
  862. for (i = 0; i < dsp_sequence->total; i++)
  863. {
  864. r = (CvRect *)cvGetSeqElem(dsp_sequence, i);
  865. printf("%4i: %4i, %4i (%ix%i)\n", i, r->x, r->y, r->width, r->height);
  866. // mark with thin red rectangle
  867. c1.x = r->x;
  868. c1.y = r->y;
  869. c2.x = r->x + r->width;
  870. c2.y = r->y + r->height;
  871. cvRectangle(image_color, c1, c2, red, 1, 8, 0);
  872. }
  873. }
  874. // 7. Save marked image to filesystem
  875. cvSaveImage("./output.png", image_color, 0);
  876. cvReleaseImage(&image);
  877. cvReleaseImage(&image_color);
  878. LOCAL_restore_cascade(cascade);
  879. cvReleaseHaarClassifierCascade(&cascade);
  880. cvReleaseMemStorage(&storage);
  881. printf("C6accel_cvHaarDetectObjects test completed successfully\n");
  882. return 1;
  883. }
  884. Int c6accel_test_Cascade(char *cascade_file_name)
  885. {
  886. CvHaarClassifierCascade *cascade;
  887. printf("Reading Cascade\n");
  888. cascade = (CvHaarClassifierCascade *)cvLoad("opencv_images/haarcascade_frontalface_alt2.xml", 0, 0, 0);
  889. printf("Reading of Cascade complete\n");
  890. traverse_and_translate_cascade(cascade);
  891. printf("Traverse and translate complete\n");
  892. printf("count: %x\n", cascade->count);
  893. LOCAL_restore_cascade(cascade);
  894. cvReleaseHaarClassifierCascade(&cascade);
  895. printf("C6accel_Cascade test completed successfully\n");
  896. return 1;
  897. }
  898. Int c6accel_test_cvGoodFeaturesToTrack(C6accel_Handle hC6accel, char *input_file_name, int n)
  899. {
  900. IplImage *input_image, *output_image, *eig_image, *temp_image;
  901. CvPoint2D32f *arm_corners, *dsp_corners, *arm_corners_rough, *dsp_corners_rough;
  902. int arm_cornerCount = 256, dsp_cornerCount = 256;
  903. CvScalar red = {0, 0, 255, 255}, black = {0, 0, 0, 255};
  904. CvPoint c1, c2;
  905. struct timeval startTime, endTime;
  906. int t_overhead, t_algo, i;
  907. printf("cvGoodFeaturesToTrack Test (%s, %i)\n", input_file_name, n);
  908. // initialize timer
  909. t_overhead = get_overhead_time();
  910. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  911. // 1. Read input image and create working images
  912. input_image = cvLoadImage(input_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  913. output_image = cvLoadImage(input_file_name, CV_LOAD_IMAGE_COLOR);
  914. eig_image = cvCreateImage(cvGetSize(input_image), 32, 1);
  915. temp_image = cvCreateImage(cvGetSize(input_image), 32, 1);
  916. // 2. Allocate output buffers
  917. arm_corners = (CvPoint2D32f *)cvAlloc(256 * sizeof(CvPoint2D32f));
  918. dsp_corners = (CvPoint2D32f *)cvAlloc(256 * sizeof(CvPoint2D32f));
  919. arm_corners_rough = (CvPoint2D32f *)cvAlloc(256 * sizeof(CvPoint2D32f));
  920. dsp_corners_rough = (CvPoint2D32f *)cvAlloc(256 * sizeof(CvPoint2D32f));
  921. // 3.a Apply ARM algorithm to find features
  922. cvGoodFeaturesToTrack(input_image, eig_image, temp_image, arm_corners, &arm_cornerCount, 0.01, 10.0, NULL, 3, 0, 0.04);
  923. gettimeofday(&startTime, NULL);
  924. for (i = 0; i < n; i++)
  925. cvGoodFeaturesToTrack(input_image, eig_image, temp_image, arm_corners, &arm_cornerCount, 0.01, 10.0, NULL, 3, 0, 0.04);
  926. gettimeofday(&endTime, NULL);
  927. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  928. printf("Called ARM GoodFeaturesToTrack function (time: %f ms)\n", t_algo / 1000.0 / n);
  929. // 3.b Apply DSP algorithm to find features
  930. C6accel_cvGoodFeaturesToTrack(hC6accel, input_image, eig_image, temp_image, dsp_corners,
  931. &dsp_cornerCount, 0.01, 10.0, NULL, 3, 0, 0.04);
  932. gettimeofday(&startTime, NULL);
  933. for (i = 0; i < n; i++)
  934. C6accel_cvGoodFeaturesToTrack(hC6accel, input_image, eig_image, temp_image, dsp_corners,
  935. &dsp_cornerCount, 0.01, 10.0, NULL, 3, 0, 0.04);
  936. gettimeofday(&endTime, NULL);
  937. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  938. printf("Called DSP GoodFeaturesToTrack function (time: %f ms)\n", t_algo / 1000.0 / n);
  939. // 4. Save rough corner locations so we can accurately benchmark the refinement functions
  940. memcpy(arm_corners_rough, arm_corners, arm_cornerCount * sizeof(CvPoint2D32f));
  941. memcpy(dsp_corners_rough, dsp_corners, dsp_cornerCount * sizeof(CvPoint2D32f));
  942. // printf("I finished memcpy\n");
  943. // 4.a Apply ARM algorithm to refine features
  944. //cvFindCorner SubPix issue to be resolved
  945. cvFindCornerSubPix(input_image, dsp_corners, dsp_cornerCount, cvSize(10, 10), cvSize(-1, -1),
  946. cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03));
  947. t_algo = 0;
  948. for (i = 0; i < n; i++)
  949. {
  950. memcpy(arm_corners, arm_corners_rough, arm_cornerCount * sizeof(CvPoint2D32f));
  951. printf("ARM Benchmark begin \n");
  952. gettimeofday(&startTime, NULL);
  953. cvFindCornerSubPix(input_image, arm_corners, arm_cornerCount, cvSize(10, 10), cvSize(-1, -1),
  954. cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03));
  955. gettimeofday(&endTime, NULL);
  956. t_algo += (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  957. }
  958. printf("Called ARM FindCornerSubPix function (time: %f ms)\n", t_algo / 1000.0 / n);
  959. // 4.b Apply DSP algorithm to refine features
  960. C6accel_cvFindCornerSubPix(hC6accel, input_image, dsp_corners, dsp_cornerCount, cvSize(10, 10), cvSize(-1, -1),
  961. cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03));
  962. t_algo = 0;
  963. for (i = 0; i < n; i++)
  964. {
  965. memcpy(dsp_corners, dsp_corners_rough, dsp_cornerCount * sizeof(CvPoint2D32f));
  966. //printf("DSP Benchmark begin \n");
  967. gettimeofday(&startTime, NULL);
  968. C6accel_cvFindCornerSubPix(hC6accel, input_image, dsp_corners, dsp_cornerCount, cvSize(10, 10), cvSize(-1, -1),
  969. cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03));
  970. gettimeofday(&endTime, NULL);
  971. t_algo += (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  972. }
  973. printf("Called DSP FindCornerSubPix function (time: %f ms)\n", t_algo / 1000.0 / n);
  974. // 5.a Mark features detected by ARM and report number of elements
  975. /* printf("ARM list contains %i features.\n", arm_cornerCount);
  976. for (i = 0; i < arm_cornerCount; i++)
  977. {
  978. //printf("%3i: (%10f,%10f) -> (%10f,%10f)\n", i,
  979. // arm_corners_rough[i].x, arm_corners_rough[i].y,
  980. // arm_corners[i].x, arm_corners[i].y);
  981. // mark with large black square
  982. c1.x = cvRound(arm_corners[i].x) - 2;
  983. c1.y = cvRound(arm_corners[i].y) - 2;
  984. c2.x = cvRound(arm_corners[i].x) + 2;
  985. c2.y = cvRound(arm_corners[i].y) + 2;
  986. cvRectangle(output_image, c1, c2, black, -1, 8, 0);
  987. }*/
  988. // 5.b Mark and print list of matches detected by DSP
  989. printf("DSP list contains %i features.\n", dsp_cornerCount);
  990. for (i = 0; i < dsp_cornerCount; i++)
  991. {
  992. //printf("%3i: (%10f,%10f) -> (%10f,%10f)\n", i,
  993. // dsp_corners_rough[i].x, dsp_corners_rough[i].y,
  994. // dsp_corners[i].x, dsp_corners[i].y);
  995. // mark with small red square
  996. c1.x = cvRound(dsp_corners[i].x) - 1;
  997. c1.y = cvRound(dsp_corners[i].y) - 1;
  998. c2.x = cvRound(dsp_corners[i].x) + 1;
  999. c2.y = cvRound(dsp_corners[i].y) + 1;
  1000. cvRectangle(output_image, c1, c2, red, -1, 8, 0);
  1001. }
  1002. // 5. Save marked image to filesystem
  1003. cvSaveImage("./output.png", output_image, 0);
  1004. printf("Saved image\n");
  1005. //6. Free memory allocated for the images
  1006. cvReleaseImage(&output_image);
  1007. cvReleaseImage(&eig_image);
  1008. cvReleaseImage(&input_image);
  1009. cvReleaseImage(&temp_image);
  1010. cvFree(&arm_corners);
  1011. cvFree(&dsp_corners);
  1012. printf("dsp_corners free\n");
  1013. printf("dsp_corner_phys: %x\n",CMEM_getPhys(dsp_corners_rough));
  1014. cvFree(&dsp_corners_rough);
  1015. cvFree(&arm_corners_rough);
  1016. printf("C6accel_cvGoodFeaturesToTrack test completed successfully\n");
  1017. return 1;
  1018. }
  1019. Int c6accel_test_cvCalcOpticalFlowPyrLK(C6accel_Handle hC6accel, char *input_file_name_1, char *input_file_name_2, int n)
  1020. {
  1021. IplImage *prev_input_image, *curr_input_image, *eig_image, *temp_image,
  1022. *prev_pyramid, *curr_pyramid,
  1023. *output_image;
  1024. CvPoint2D32f *prev_corners, *arm_curr_corners, *dsp_curr_corners;
  1025. char *arm_status, *dsp_status;
  1026. int arm_cornerCount = 1024, dsp_cornerCount = 1024;
  1027. CvScalar red = {0, 0, 255, 255}, black = {0, 0, 0, 255};
  1028. CvPoint c1, c2;
  1029. struct timeval startTime, endTime;
  1030. int t_overhead, t_algo, i;
  1031. printf("cvCalcOpticalFlowPyrLK Test (%s -> %s, %i)\n", input_file_name_1, input_file_name_2, n);
  1032. // initialize timer
  1033. t_overhead = get_overhead_time();
  1034. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1035. // 1. Read input image and create working images
  1036. prev_input_image = cvLoadImage(input_file_name_1, CV_LOAD_IMAGE_GRAYSCALE);
  1037. curr_input_image = cvLoadImage(input_file_name_2, CV_LOAD_IMAGE_GRAYSCALE);
  1038. output_image = cvLoadImage(input_file_name_2, CV_LOAD_IMAGE_COLOR);
  1039. eig_image = cvCreateImage(cvGetSize(prev_input_image), 32, 1);
  1040. temp_image = cvCreateImage(cvGetSize(prev_input_image), 32, 1);
  1041. prev_pyramid = cvCreateImage(cvGetSize(prev_input_image), 8, 1);
  1042. curr_pyramid = cvCreateImage(cvGetSize(prev_input_image), 8, 1);
  1043. // 2. Allocate output buffers
  1044. prev_corners = (CvPoint2D32f *)cvAlloc(arm_cornerCount * sizeof(CvPoint2D32f));
  1045. arm_curr_corners = (CvPoint2D32f *)cvAlloc(arm_cornerCount * sizeof(CvPoint2D32f));
  1046. dsp_curr_corners = (CvPoint2D32f *)cvAlloc(dsp_cornerCount * sizeof(CvPoint2D32f));
  1047. arm_status = (char *)cvAlloc(arm_cornerCount * sizeof(char));
  1048. dsp_status = (char *)cvAlloc(dsp_cornerCount * sizeof(char));
  1049. // 3. Apply ARM algorithm to find features
  1050. cvGoodFeaturesToTrack(prev_input_image, eig_image, temp_image, prev_corners, &arm_cornerCount, 0.01, 10.0, NULL, 3, 0, 0.04);
  1051. dsp_cornerCount = arm_cornerCount;
  1052. // 4.a Apply ARM algorithm to refine features
  1053. cvCalcOpticalFlowPyrLK(prev_input_image, curr_input_image, prev_pyramid, curr_pyramid,
  1054. prev_corners, arm_curr_corners, arm_cornerCount, cvSize(10, 10), 3,
  1055. arm_status, NULL, cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03), 0);
  1056. gettimeofday(&startTime, NULL);
  1057. for (i = 0; i < n; i++)
  1058. {
  1059. cvCalcOpticalFlowPyrLK(prev_input_image, curr_input_image, prev_pyramid, curr_pyramid,
  1060. prev_corners, arm_curr_corners, arm_cornerCount, cvSize(10, 10), 3,
  1061. arm_status, NULL, cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03), 0);
  1062. }
  1063. gettimeofday(&endTime, NULL);
  1064. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1065. printf("Called ARM cvCalcOpticalFlowPyrLK function (time: %f ms)\n", t_algo / 1000.0 / n);
  1066. // 4.b Apply DSP algorithm to refine features
  1067. C6accel_cvCalcOpticalFlowPyrLK(hC6accel, prev_input_image, curr_input_image, prev_pyramid, curr_pyramid,
  1068. prev_corners, dsp_curr_corners, dsp_cornerCount, cvSize(10, 10), 3,
  1069. dsp_status, NULL, cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03), 0);
  1070. gettimeofday(&startTime, NULL);
  1071. for (i = 0; i < n; i++)
  1072. {
  1073. C6accel_cvCalcOpticalFlowPyrLK(hC6accel, prev_input_image, curr_input_image, prev_pyramid, curr_pyramid,
  1074. prev_corners, dsp_curr_corners, dsp_cornerCount, cvSize(10, 10), 3,
  1075. dsp_status, NULL, cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03), 0);
  1076. }
  1077. gettimeofday(&endTime, NULL);
  1078. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1079. printf("Called DSP cvCalcOpticalFlowPyrLK function (time: %f ms)\n", t_algo / 1000.0 / n);
  1080. // 5.a Mark motion detected by ARM and report number of elements
  1081. printf("ARM list contains %i features.\n", arm_cornerCount);
  1082. for (i = 0; i < arm_cornerCount; i++)
  1083. {
  1084. //printf("%3i: (%10f,%10f) -> (%10f,%10f)\n", i,
  1085. // arm_corners_rough[i].x, arm_corners_rough[i].y,
  1086. // arm_corners[i].x, arm_corners[i].y);
  1087. // mark with thick black line
  1088. c1.x = cvRound(prev_corners[i].x);
  1089. c1.y = cvRound(prev_corners[i].y);
  1090. c2.x = cvRound(arm_curr_corners[i].x);
  1091. c2.y = cvRound(arm_curr_corners[i].y);
  1092. cvCircle(
  1093. output_image,
  1094. c1,
  1095. 2,
  1096. CVX_GRAY50,
  1097. -1,8,0
  1098. );
  1099. //cvLine(output_image, c1, c2, black, 2, 8, 0);
  1100. }
  1101. // 5.b Mark and print list of matches detected by DSP
  1102. printf("DSP list contains %i features.\n", dsp_cornerCount);
  1103. for (i = 0; i < dsp_cornerCount; i++)
  1104. {
  1105. //printf("%3i: (%10f,%10f) -> (%10f,%10f)\n", i,
  1106. // dsp_corners_rough[i].x, dsp_corners_rough[i].y,
  1107. // dsp_corners[i].x, dsp_corners[i].y);
  1108. // mark with thin red line
  1109. c1.x = cvRound(prev_corners[i].x);
  1110. c1.y = cvRound(prev_corners[i].y);
  1111. c2.x = cvRound(dsp_curr_corners[i].x);
  1112. c2.y = cvRound(dsp_curr_corners[i].y);
  1113. cvLine(output_image, c1, c2, red, 1, 8, 0);
  1114. }
  1115. // 5. Save marked image to filesystem
  1116. cvSaveImage("./output.png", output_image, 0);
  1117. cvReleaseImage(&prev_input_image);
  1118. cvReleaseImage(&curr_input_image);
  1119. cvReleaseImage(&output_image);
  1120. cvReleaseImage(&eig_image);
  1121. cvReleaseImage(&temp_image);
  1122. cvReleaseImage(&prev_pyramid);
  1123. cvReleaseImage(&curr_pyramid);
  1124. // 2. Allocate output buffers
  1125. prev_corners = cvFree(&prev_corners);
  1126. arm_curr_corners = cvFree(&arm_curr_corners);
  1127. dsp_curr_corners = cvFree(&dsp_curr_corners);
  1128. arm_status = cvFree(&arm_status);
  1129. dsp_status = cvFree(&dsp_status);
  1130. printf("C6accel_cvCalcOpticalFlowPyrLK test completed successfully\n");
  1131. return 1;
  1132. }
  1133. Int c6accel_test_cvMatchTemplate(C6accel_Handle hC6accel, char *input_file_name, char *template_file_name, int n)
  1134. {
  1135. IplImage *input_image, *template_image, *arm_output_image, *dsp_output_image,
  1136. *arm_scale_image, *dsp_scale_image;
  1137. CvSize output_size;
  1138. struct timeval startTime, endTime;
  1139. int t_overhead, t_algo, i;
  1140. printf("cvMatchTemplate Test (%s, %s, %i)\n", input_file_name, template_file_name, n);
  1141. // initialize timer
  1142. t_overhead = get_overhead_time();
  1143. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1144. // 1. Read input and template images
  1145. input_image = cvLoadImage(input_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  1146. template_image = cvLoadImage(template_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  1147. // 2. Allocate output images
  1148. output_size = cvSize(input_image->width - template_image->width + 1,
  1149. input_image->height - template_image->height + 1);
  1150. arm_output_image = cvCreateImage(output_size, 32, 1);
  1151. arm_scale_image = cvCreateImage(output_size, 8, 1);
  1152. dsp_output_image = cvCreateImage(output_size, 32, 1);
  1153. dsp_scale_image = cvCreateImage(output_size, 8, 1);
  1154. cvSetZero(arm_output_image);
  1155. cvSetZero(dsp_output_image);
  1156. // 3.a Apply ARM algorithm to match template
  1157. cvMatchTemplate(input_image, template_image, arm_output_image, CV_TM_SQDIFF);
  1158. gettimeofday(&startTime, NULL);
  1159. for (i = 0; i < n; i++)
  1160. cvMatchTemplate(input_image, template_image, arm_output_image, CV_TM_SQDIFF);
  1161. gettimeofday(&endTime, NULL);
  1162. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1163. printf("Called ARM cvMatchTemplate function (time: %f ms)\n", t_algo / 1000.0 / n);
  1164. // 4.b Apply DSP algorithm to refine features
  1165. C6accel_cvMatchTemplate(hC6accel, input_image, template_image, dsp_output_image, CV_TM_SQDIFF);
  1166. gettimeofday(&startTime, NULL);
  1167. for (i = 0; i < n; i++)
  1168. C6accel_cvMatchTemplate(hC6accel, input_image, template_image, dsp_output_image, CV_TM_SQDIFF);
  1169. gettimeofday(&endTime, NULL);
  1170. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1171. printf("Called DSP cvMatchTemplate function (time: %f ms)\n", t_algo / 1000.0 / n);
  1172. // 5. Normalize output images
  1173. cvNormalize(arm_output_image, arm_scale_image, 0, 255, CV_MINMAX, NULL);
  1174. cvNormalize(dsp_output_image, dsp_scale_image, 0, 255, CV_MINMAX, NULL);
  1175. // 6. Compare outputs
  1176. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(arm_scale_image, dsp_scale_image, CV_L2, NULL));
  1177. // 7. Save output images to filesystem
  1178. cvSaveImage("./output_arm.png", arm_scale_image, 0);
  1179. cvSaveImage("./output_dsp.png", dsp_scale_image, 0);
  1180. // 8. Free memory allocated to images
  1181. cvReleaseImage(&template_image);
  1182. cvReleaseImage(&input_image);
  1183. cvReleaseImage(&arm_output_image);
  1184. cvReleaseImage(&arm_scale_image);
  1185. cvReleaseImage(&dsp_output_image);
  1186. cvReleaseImage(&dsp_scale_image);
  1187. printf("C6accel_cvMatchTemplate test completed successfully\n");
  1188. return 1;
  1189. }
  1190. Int c6accel_test_cvMulSpectrums(C6accel_Handle hC6accel, char *input_file_name_1, char *input_file_name_2, int n)
  1191. {
  1192. IplImage *input_image_1, *input_image_2, *input_image_1f, *input_image_2f,
  1193. *dft_image_1, *dft_image_2,
  1194. *arm_mult_image, *dsp_mult_image, *arm_idft_image,
  1195. *dsp_idft_image, *arm_norm_image, *dsp_norm_image;
  1196. CvSize dft_size;
  1197. struct timeval startTime, endTime;
  1198. int t_overhead, t_algo, i;
  1199. printf("cvMulSpectrums Test (%s, %s, %i)\n", input_file_name_1, input_file_name_2, n);
  1200. // initialize timer
  1201. t_overhead = get_overhead_time();
  1202. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1203. // 1. Read input images and check that sizes match
  1204. input_image_1 = cvLoadImage(input_file_name_1, CV_LOAD_IMAGE_GRAYSCALE);
  1205. input_image_2 = cvLoadImage(input_file_name_2, CV_LOAD_IMAGE_GRAYSCALE);
  1206. if ((input_image_1->width != input_image_2->width) ||
  1207. (input_image_1->height != input_image_2->height))
  1208. {
  1209. printf("Image size mismatch; cvMulSpectrums Test aborted!\n");
  1210. return -1;
  1211. }
  1212. // 2. Allocate working and output images (and convert input images to floating point)
  1213. dft_size = cvSize(input_image_1->width, input_image_1->height);
  1214. input_image_1f = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1215. input_image_2f = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1216. dft_image_1 = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1217. dft_image_2 = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1218. arm_mult_image = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1219. arm_idft_image = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1220. arm_norm_image = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1221. dsp_mult_image = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1222. dsp_idft_image = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1223. dsp_norm_image = cvCreateImage(dft_size, IPL_DEPTH_32F, 1);
  1224. cvConvertScale(input_image_1, input_image_1f, 1.0f / 255.0f, 0);
  1225. cvConvertScale(input_image_2, input_image_2f, 1.0f / 255.0f, 0);
  1226. // 3. Apply ARM algorithm to calculate DFT for images 1, 2 (don't time)
  1227. cvDFT(input_image_1f, dft_image_1, CV_DXT_FORWARD, 0);
  1228. cvDFT(input_image_2f, dft_image_2, CV_DXT_FORWARD, 0);
  1229. // 4.a Apply ARM algorithm to multiply spectrums
  1230. cvMulSpectrums(dft_image_1, dft_image_2, arm_mult_image, 0);
  1231. gettimeofday(&startTime, NULL);
  1232. for (i = 0; i < n; i++)
  1233. cvMulSpectrums(dft_image_1, dft_image_2, arm_mult_image, 0);
  1234. gettimeofday(&endTime, NULL);
  1235. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1236. printf("Called ARM cvMulSpectrums function (time: %f ms)\n", t_algo / 1000.0 / n);
  1237. // 4.b Apply DSP algorithm to multiply spectrums
  1238. C6accel_cvMulSpectrums(hC6accel, dft_image_1, dft_image_2, dsp_mult_image, 0);
  1239. gettimeofday(&startTime, NULL);
  1240. for (i = 0; i < n; i++)
  1241. C6accel_cvMulSpectrums(hC6accel, dft_image_1, dft_image_2, dsp_mult_image, 0);
  1242. gettimeofday(&endTime, NULL);
  1243. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1244. printf("Called DSP cvMulSpectrums function (time: %f ms)\n", t_algo / 1000.0 / n);
  1245. // 5.a Apply ARM IDFT algorithm
  1246. cvDFT(arm_mult_image, arm_idft_image, CV_DXT_INVERSE, 0);
  1247. gettimeofday(&startTime, NULL);
  1248. for (i = 0; i < n; i++)
  1249. cvDFT(arm_mult_image, arm_idft_image, CV_DXT_INVERSE, 0);
  1250. gettimeofday(&endTime, NULL);
  1251. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1252. printf("Called ARM cvDFT function (time: %f ms)\n", t_algo / 1000.0 / n);
  1253. // 5.b Apply DSP IDFT algorithm
  1254. C6accel_cvDFT(hC6accel, dsp_mult_image, dsp_idft_image, CV_DXT_INVERSE, 0);
  1255. gettimeofday(&startTime, NULL);
  1256. for (i = 0; i < n; i++)
  1257. C6accel_cvDFT(hC6accel, dsp_mult_image, dsp_idft_image, CV_DXT_INVERSE, 0);
  1258. gettimeofday(&endTime, NULL);
  1259. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1260. printf("Called DSP cvDFT function (time: %f ms)\n", t_algo / 1000.0 / n);
  1261. // 6.a Apply ARM algorithm to normalize image
  1262. cvNormalize(arm_idft_image, arm_norm_image, 0, 255, CV_MINMAX, NULL);
  1263. gettimeofday(&startTime, NULL);
  1264. for (i = 0; i < n; i++)
  1265. cvNormalize(arm_idft_image, arm_norm_image, 0, 255, CV_MINMAX, NULL);
  1266. gettimeofday(&endTime, NULL);
  1267. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1268. printf("Called ARM cvNormalize function (time: %f ms)\n", t_algo / 1000.0 / n);
  1269. // 6.b Apply DSP algorithm to normalize image
  1270. C6accel_cvNormalize(hC6accel, dsp_idft_image, dsp_norm_image, 0, 255, CV_MINMAX, NULL);
  1271. gettimeofday(&startTime, NULL);
  1272. for (i = 0; i < n; i++)
  1273. C6accel_cvNormalize(hC6accel, dsp_idft_image, dsp_norm_image, 0, 255, CV_MINMAX, NULL);
  1274. gettimeofday(&endTime, NULL);
  1275. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1276. printf("Called DSP cvNormalize function (time: %f ms)\n", t_algo / 1000.0 / n);
  1277. // 7. Compare outputs
  1278. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(arm_norm_image, dsp_norm_image, CV_L2, NULL));
  1279. // 8. Save output images to filesystem
  1280. cvSaveImage("./output_arm.png", arm_norm_image, 0);
  1281. cvSaveImage("./output_dsp.png", dsp_norm_image, 0);
  1282. //9. Free memory allocated to the images
  1283. cvReleaseImage(&input_image_1);
  1284. cvReleaseImage(&input_image_2);
  1285. cvReleaseImage(&dft_image_1);
  1286. cvReleaseImage(&dft_image_2);
  1287. cvReleaseImage(&input_image_1f);
  1288. cvReleaseImage(&input_image_2f);
  1289. cvReleaseImage(&arm_mult_image);
  1290. cvReleaseImage(&arm_idft_image);
  1291. cvReleaseImage(&arm_norm_image);
  1292. cvReleaseImage(&dsp_mult_image);
  1293. cvReleaseImage(&dsp_idft_image);
  1294. cvReleaseImage(&dsp_norm_image);
  1295. printf("C6accel_cvMulSpectrums test completed successfully\n");
  1296. return 1;
  1297. }
  1298. Int c6accel_test_cvNorm(C6accel_Handle hC6accel, char *input_file_name, int n)
  1299. {
  1300. IplImage *input_image;
  1301. double arm_min_val, arm_max_val, dsp_min_val, dsp_max_val,
  1302. arm_norm, dsp_norm;
  1303. CvPoint arm_min_loc, arm_max_loc, dsp_min_loc, dsp_max_loc;
  1304. struct timeval startTime, endTime;
  1305. int t_overhead, t_algo, i;
  1306. printf("cvNorm Test (%s, %i)\n", input_file_name, n);
  1307. // initialize timer
  1308. t_overhead = get_overhead_time();
  1309. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1310. // 1. Read input image
  1311. input_image = cvLoadImage(input_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  1312. // 2.a Apply ARM algorithm to find min/max pixels
  1313. cvMinMaxLoc(input_image, &arm_min_val, &arm_max_val, &arm_min_loc, &arm_max_loc, NULL);
  1314. gettimeofday(&startTime, NULL);
  1315. for (i = 0; i < n; i++)
  1316. cvMinMaxLoc(input_image, &arm_min_val, &arm_max_val, &arm_min_loc, &arm_max_loc, NULL);
  1317. gettimeofday(&endTime, NULL);
  1318. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1319. printf("Called ARM cvMinMaxLoc function (time: %f ms)\n", t_algo / 1000.0 / n);
  1320. // 2.b Apply DSP algorithm to find min/max pixels
  1321. C6accel_cvMinMaxLoc(hC6accel, input_image, &dsp_min_val, &dsp_max_val, &dsp_min_loc, &dsp_max_loc, NULL);
  1322. gettimeofday(&startTime, NULL);
  1323. for (i = 0; i < n; i++)
  1324. C6accel_cvMinMaxLoc(hC6accel, input_image, &dsp_min_val, &dsp_max_val, &dsp_min_loc, &dsp_max_loc, NULL);
  1325. gettimeofday(&endTime, NULL);
  1326. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1327. printf("Called DSP cvMinMaxLoc function (time: %f ms)\n", t_algo / 1000.0 / n);
  1328. // 3.a Apply ARM algorithm to find norm
  1329. arm_norm = cvNorm(input_image, NULL, CV_L2, NULL);
  1330. gettimeofday(&startTime, NULL);
  1331. for (i = 0; i < n; i++)
  1332. arm_norm = cvNorm(input_image, NULL, CV_L2, NULL);
  1333. gettimeofday(&endTime, NULL);
  1334. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1335. printf("Called ARM cvNorm function (time: %f ms)\n", t_algo / 1000.0 / n);
  1336. // 3.b Apply DSP algorithm to find norm
  1337. C6accel_cvNorm(hC6accel, input_image, NULL, CV_L2, NULL, &dsp_norm);
  1338. gettimeofday(&startTime, NULL);
  1339. for (i = 0; i < n; i++)
  1340. C6accel_cvNorm(hC6accel, input_image, NULL, CV_L2, NULL, &dsp_norm);
  1341. gettimeofday(&endTime, NULL);
  1342. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1343. printf("Called DSP cvNorm function (time: %f ms)\n", t_algo / 1000.0 / n);
  1344. // 4. Compare outputs
  1345. printf("ARM image statistics:\n\tL2 Norm:\t%f\n\tMin Val:\t%f\t(%i, %i)\n\tMax Val:\t%f\t(%i, %i)\n",
  1346. arm_norm, arm_min_val, arm_min_loc.x, arm_min_loc.y, arm_max_val, arm_max_loc.x, arm_max_loc.y);
  1347. printf("DSP image statistics:\n\tL2 Norm:\t%f\n\tMin Val:\t%f\t(%i, %i)\n\tMax Val:\t%f\t(%i, %i)\n",
  1348. dsp_norm, dsp_min_val, dsp_min_loc.x, dsp_min_loc.y, dsp_max_val, dsp_max_loc.x, dsp_max_loc.y);
  1349. cvReleaseImage(&input_image);
  1350. printf("C6accel_cvNorm test completed successfully\n");
  1351. return 1;
  1352. }
  1353. Int c6accel_test_cvIntegral(C6accel_Handle hC6accel, char *input_file_name, int n)
  1354. {
  1355. IplImage *input_image, *arm_sum_image, *arm_norm_image,
  1356. *dsp_sum_image, *dsp_norm_image;
  1357. CvSize integral_size;
  1358. struct timeval startTime, endTime;
  1359. int t_overhead, t_algo, i;
  1360. printf("cvIntegral Test (%s, %i)\n", input_file_name, n);
  1361. // initialize timer
  1362. t_overhead = get_overhead_time();
  1363. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1364. // 1. Read input image
  1365. input_image = cvLoadImage(input_file_name, CV_LOAD_IMAGE_GRAYSCALE);
  1366. // 2. Create output images
  1367. integral_size = cvSize(input_image->width + 1, input_image->height + 1);
  1368. arm_sum_image = cvCreateImage(integral_size, IPL_DEPTH_32S, 1);
  1369. arm_norm_image = cvCreateImage(integral_size, IPL_DEPTH_32S, 1);
  1370. dsp_sum_image = cvCreateImage(integral_size, IPL_DEPTH_32S, 1);
  1371. dsp_norm_image = cvCreateImage(integral_size, IPL_DEPTH_32S, 1);
  1372. // 3.a Apply ARM integral algorithm
  1373. cvIntegral(input_image, arm_sum_image, NULL, NULL);
  1374. gettimeofday(&startTime, NULL);
  1375. for (i = 0; i < n; i++)
  1376. cvIntegral(input_image, arm_sum_image, NULL, NULL);
  1377. gettimeofday(&endTime, NULL);
  1378. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1379. printf("Called ARM cvIntegral function (time: %f ms)\n", t_algo / 1000.0 / n);
  1380. // 3.b Apply DSP integral algorithm
  1381. C6accel_cvIntegral(hC6accel, input_image, dsp_sum_image, NULL, NULL);
  1382. gettimeofday(&startTime, NULL);
  1383. for (i = 0; i < n; i++)
  1384. C6accel_cvIntegral(hC6accel, input_image, dsp_sum_image, NULL, NULL);
  1385. gettimeofday(&endTime, NULL);
  1386. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1387. printf("Called DSP cvIntegral function (time: %f ms)\n", t_algo / 1000.0 / n);
  1388. // 4. Normalize output images
  1389. cvNormalize(arm_sum_image, arm_norm_image, 0, 255, CV_MINMAX, NULL);
  1390. cvNormalize(dsp_sum_image, dsp_norm_image, 0, 255, CV_MINMAX, NULL);
  1391. // 5. Compare outputs
  1392. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(arm_norm_image, dsp_norm_image, CV_L2, NULL));
  1393. // 6. Save output images to filesystem
  1394. cvSaveImage("./output_arm.png", arm_norm_image, 0);
  1395. cvSaveImage("./output_dsp.png", dsp_norm_image, 0);
  1396. // 7. Free memory allocated to images
  1397. cvReleaseImage(&input_image);
  1398. cvReleaseImage(&arm_sum_image);
  1399. cvReleaseImage(&arm_norm_image);
  1400. cvReleaseImage(&dsp_sum_image);
  1401. cvReleaseImage(&dsp_norm_image);
  1402. printf("C6accel_cvIntegral test completed successfully\n");
  1403. return 1;
  1404. }
  1405. Int c6accel_test_cvAdd(C6accel_Handle hC6accel, char *input_file_name1,char *input_file_name2, int n)
  1406. {
  1407. IplImage *inputImg1,*inputImg2, *outputImg_arm, *outputImg_dsp;
  1408. struct timeval startTime, endTime;
  1409. int t_overhead, t_algo, i;
  1410. float t_avg;
  1411. printf("cvAdd Test (%s, %i iterations)\n", input_file_name1, n);
  1412. // initialize timer
  1413. t_overhead = get_overhead_time();
  1414. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1415. // 1. Read input images from file
  1416. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1417. inputImg2 = cvLoadImage( input_file_name2, CV_LOAD_IMAGE_COLOR);
  1418. // 2. Allocate output images (must have same depth, channels as input)
  1419. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1420. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1421. // 3.a Apply ARM algorithm
  1422. cvAdd(inputImg1,inputImg2,outputImg_arm,NULL); // run once before timing
  1423. gettimeofday(&startTime, NULL);
  1424. for (i = 0; i < n; i++)
  1425. cvAdd(inputImg1,inputImg2, outputImg_arm, NULL);
  1426. gettimeofday(&endTime, NULL);
  1427. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1428. t_avg = (float)t_algo / (float)n;
  1429. printf("Called ARM Add function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1430. // 3.b Apply DSP algorithm
  1431. C6accel_cvAdd(hC6accel, inputImg1,inputImg2,outputImg_dsp,NULL); // run once before timing
  1432. gettimeofday(&startTime, NULL);
  1433. for (i = 0; i < n; i++)
  1434. C6accel_cvAdd(hC6accel, inputImg1, inputImg2, outputImg_dsp,NULL);
  1435. gettimeofday(&endTime, NULL);
  1436. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1437. t_avg = (float)t_algo / (float)n;
  1438. printf("Called DSP Add function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1439. // 4. Compare outputs
  1440. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  1441. // 5. Save outputs to filesystem
  1442. cvSaveImage("./output_arm.png", outputImg_arm, 0);
  1443. cvSaveImage("./output_dsp.png", outputImg_dsp, 0);
  1444. // 6. Free memory allocated to images
  1445. cvReleaseImage(&inputImg1);
  1446. cvReleaseImage(&inputImg2);
  1447. cvReleaseImage(&outputImg_arm);
  1448. cvReleaseImage(&outputImg_dsp);
  1449. printf("C6accel_cvAdd test completed successfully; outputs saved to filesystem\n");
  1450. return 1;
  1451. }
  1452. Int c6accel_test_cvAddS(C6accel_Handle hC6accel, char *input_file_name1, int n)
  1453. {
  1454. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp;
  1455. struct timeval startTime, endTime;
  1456. int t_overhead, t_algo, i;
  1457. float t_avg;
  1458. CvScalar red = {0, 0, 255, 255};
  1459. printf("cvAddS Test (%s, %i iterations)\n", input_file_name1, n);
  1460. // initialize timer
  1461. t_overhead = get_overhead_time();
  1462. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1463. // 1. Read input images from file
  1464. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1465. // 2. Allocate output images (must have same depth, channels as input)
  1466. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1467. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1468. // 3.a Apply ARM algorithm
  1469. cvAddS(inputImg1,red,outputImg_arm,NULL); // run once before timing
  1470. gettimeofday(&startTime, NULL);
  1471. for (i = 0; i < n; i++)
  1472. cvAddS(inputImg1,red, outputImg_arm, NULL);
  1473. gettimeofday(&endTime, NULL);
  1474. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1475. t_avg = (float)t_algo / (float)n;
  1476. printf("Called ARM Add function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1477. // 3.b Apply DSP algorithm
  1478. C6accel_cvAddS(hC6accel, inputImg1,red,outputImg_dsp,NULL); // run once before timing
  1479. gettimeofday(&startTime, NULL);
  1480. for (i = 0; i < n; i++)
  1481. C6accel_cvAddS(hC6accel, inputImg1, red, outputImg_dsp,NULL);
  1482. gettimeofday(&endTime, NULL);
  1483. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1484. t_avg = (float)t_algo / (float)n;
  1485. printf("Called DSP AddS function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1486. // 5. Compare outputs
  1487. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  1488. // 6. Save outputs to filesystem
  1489. cvSaveImage("./output_arm.png", outputImg_arm, 0);
  1490. cvSaveImage("./output_dsp.png", outputImg_dsp, 0);
  1491. //7. Free memory allocated to images
  1492. cvReleaseImage(&inputImg1);
  1493. cvReleaseImage(&outputImg_arm);
  1494. cvReleaseImage(&outputImg_dsp);
  1495. printf("C6accel_cvAddS test completed successfully; outputs saved to filesystem\n");
  1496. return 1;
  1497. }
  1498. Int c6accel_test_cvAbsDiff(C6accel_Handle hC6accel, char *input_file_name1,char *input_file_name2, int n)
  1499. {
  1500. IplImage *inputImg1,*inputImg2, *outputImg_arm, *outputImg_dsp;
  1501. struct timeval startTime, endTime;
  1502. int t_overhead, t_algo, i;
  1503. float t_avg;
  1504. printf("cvAbsDiff Test (%s, %i iterations)\n", input_file_name1, n);
  1505. // initialize timer
  1506. t_overhead = get_overhead_time();
  1507. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1508. // 1. Read input images from file
  1509. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1510. inputImg2 = cvLoadImage( input_file_name2, CV_LOAD_IMAGE_COLOR);
  1511. // 2. Allocate output images (must have same depth, channels as input)
  1512. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1513. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1514. // 3.a Apply ARM algorithm
  1515. cvAbsDiff(inputImg1,inputImg2,outputImg_arm); // run once before timing
  1516. gettimeofday(&startTime, NULL);
  1517. for (i = 0; i < n; i++)
  1518. cvAbsDiff(inputImg1,inputImg2, outputImg_arm);
  1519. gettimeofday(&endTime, NULL);
  1520. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1521. t_avg = (float)t_algo / (float)n;
  1522. printf("Called ARM AbsDiff function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1523. // 3.b Apply DSP algorithm
  1524. C6accel_cvAbsDiff(hC6accel, inputImg1,inputImg2,outputImg_dsp); // run once before timing
  1525. gettimeofday(&startTime, NULL);
  1526. for (i = 0; i < n; i++)
  1527. C6accel_cvAbsDiff(hC6accel, inputImg1, inputImg2, outputImg_dsp);
  1528. gettimeofday(&endTime, NULL);
  1529. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1530. t_avg = (float)t_algo / (float)n;
  1531. printf("Called DSP AbsDiff function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1532. // 5. Compare outputs
  1533. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  1534. // 6. Save outputs to filesystem
  1535. cvSaveImage("./output_arm.png", outputImg_arm, 0);
  1536. cvSaveImage("./output_dsp.png", outputImg_dsp, 0);
  1537. //7. Free memeory allocated to images
  1538. cvReleaseImage(&inputImg1);
  1539. cvReleaseImage(&inputImg2);
  1540. cvReleaseImage(&outputImg_arm);
  1541. cvReleaseImage(&outputImg_dsp);
  1542. printf("C6accel_cvAbsDiff test completed successfully; outputs saved to filesystem\n");
  1543. return 1;
  1544. }
  1545. Int c6accel_test_cvAbsDiffS(C6accel_Handle hC6accel, char *input_file_name1, int n)
  1546. {
  1547. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp;
  1548. struct timeval startTime, endTime;
  1549. int t_overhead, t_algo, i;
  1550. float t_avg;
  1551. CvScalar value = cvScalarAll(0.0);
  1552. printf("cvAbsDiffS Test (%s, %i iterations)\n", input_file_name1, n);
  1553. // initialize timer
  1554. t_overhead = get_overhead_time();
  1555. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1556. // 1. Read input images from file
  1557. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1558. // 2. Allocate output images (must have same depth, channels as input)
  1559. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1560. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1561. // 3.a Apply ARM algorithm
  1562. cvAbsDiffS(inputImg1,outputImg_arm,value); // run once before timing
  1563. gettimeofday(&startTime, NULL);
  1564. for (i = 0; i < n; i++)
  1565. cvAbsDiffS(inputImg1, outputImg_arm,value);
  1566. gettimeofday(&endTime, NULL);
  1567. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1568. t_avg = (float)t_algo / (float)n;
  1569. printf("Called ARM AbsDiffS function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1570. // 3.b Apply DSP algorithm
  1571. C6accel_cvAbsDiffS(hC6accel, inputImg1,outputImg_arm,value); // run once before timing
  1572. gettimeofday(&startTime, NULL);
  1573. for (i = 0; i < n; i++)
  1574. C6accel_cvAbsDiffS(hC6accel, inputImg1, outputImg_dsp,value);
  1575. gettimeofday(&endTime, NULL);
  1576. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1577. t_avg = (float)t_algo / (float)n;
  1578. printf("Called DSP AbsDiffS function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1579. // 4. Compare outputs
  1580. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  1581. // 5. Save outputs to filesystem
  1582. cvSaveImage("./output_arm.png", outputImg_arm, 0);
  1583. cvSaveImage("./output_dsp.png", outputImg_dsp, 0);
  1584. //6. Free memory allocated to images
  1585. cvReleaseImage(&inputImg1);
  1586. cvReleaseImage(&outputImg_arm);
  1587. cvReleaseImage(&outputImg_dsp);
  1588. printf("C6accel_cvAbsDiffS test completed successfully; outputs saved to filesystem\n");
  1589. return 1;
  1590. }
  1591. Int C6accel_test_contours(C6accel_Handle hC6accel, char *input_file_name1, int n)
  1592. {
  1593. IplImage *inputImg1, *inputImg2, *outputImg_arm, *outputImg_dsp;
  1594. IplImage* g_gray = NULL;
  1595. double g_thresh = 100.0;
  1596. CvSeq* contours = 0, *contour2;
  1597. CvMemStorage* g_storage = NULL;
  1598. int status;
  1599. struct timeval startTime, endTime;
  1600. int t_overhead=0, t_algo, i;
  1601. double t_br_arm=0.0, t_dc_arm=0.0, t_ca_arm=0.0,t_br_dsp=0.0, t_dc_dsp=0.0, t_ca_dsp=0.0;
  1602. float t_avg;
  1603. CvScalar value = cvScalarAll(0.0);
  1604. CvRect boundbox;
  1605. double area,area_arm,area_dsp, Total_area_arm, Total_area_dsp;
  1606. //Important: For DSP implementation pass pointer and allocate memroy from CMEM
  1607. CvRect *boundbox_ptr;
  1608. void *temp_ptr;
  1609. printf("cvThreshold Test (%s, %i iterations)\n", input_file_name1, n);
  1610. // initialize timer
  1611. t_overhead = get_overhead_time();
  1612. printf("(Overhead time is %f ms.)\n", t_overhead / 1000.0);
  1613. // 1. Read input images from file
  1614. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1615. inputImg2 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1616. //allocate memory for CvRect from CMEM
  1617. boundbox_ptr=Memory_alloc(sizeof(CvRect), &testfxnsMemParams);
  1618. // 2. Allocate output images (must have same depth, channels as input)
  1619. // cvThreshold supports only single chanel output(8bit)
  1620. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), 8,1);
  1621. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), 8,1);
  1622. g_gray = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),8,1);
  1623. //3. Create storage for the contour
  1624. g_storage = cvCreateMemStorage(0);
  1625. temp_ptr = cvMemStorageAlloc(g_storage, 64);
  1626. contours = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvPoint), g_storage);
  1627. cvCvtColor( inputImg1, g_gray, CV_BGR2GRAY );
  1628. gettimeofday(&startTime, NULL);
  1629. // 3.a Apply ARM algorithm
  1630. for (i = 0; i < n; i++)
  1631. cvThreshold(g_gray, outputImg_arm , g_thresh, 255.0, CV_THRESH_BINARY );
  1632. gettimeofday(&endTime, NULL);
  1633. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1634. t_avg = (float)t_algo / (float)n;
  1635. printf("Called ARM cvThreshold function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1636. // 3.b Apply DSP algorithm
  1637. gettimeofday(&startTime, NULL);
  1638. for (i = 0; i < n; i++)
  1639. status = C6accel_cvThreshold(hC6accel, g_gray, outputImg_dsp , g_thresh, 255.0, CV_THRESH_BINARY );
  1640. gettimeofday(&endTime, NULL);
  1641. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1642. t_avg = (float)t_algo / (float)n;
  1643. printf("Called DSP cvThreshold function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1644. // 5. Compare outputs
  1645. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  1646. cvSaveImage("./output_arm_thresh.png",outputImg_arm , 0);
  1647. cvSaveImage("./output_dsp_thresh.png",outputImg_dsp , 0);
  1648. printf("Find Contours Called\n");
  1649. //6 Test for drawing functions and contour features :Bounding Rect, DrawContours, ContourArea
  1650. C6accel_cvFindContours(hC6accel,outputImg_arm, g_storage, &contours, sizeof(CvContour),CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0) );
  1651. printf("Find Contours Complete\n");
  1652. gettimeofday(&startTime, NULL);
  1653. boundbox = cvBoundingRect(contours,1);
  1654. gettimeofday(&endTime, NULL);
  1655. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1656. t_avg = (float)t_algo / (float)n;
  1657. printf("Called ARM cvBoundingRect function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1658. gettimeofday(&startTime, NULL);
  1659. C6accel_cvBoundingRect(hC6accel,contours,boundbox_ptr,1);
  1660. gettimeofday(&endTime, NULL);
  1661. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1662. t_avg = (float)t_algo / (float)n;
  1663. printf("Called DSP cvBoundingRect function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1664. gettimeofday(&startTime, NULL);
  1665. cvDrawContours(inputImg1, contours,CV_RGB(255,0,0),CV_RGB(0,255,0),-1, 1,8, cvPoint(0,0) );
  1666. gettimeofday(&endTime, NULL);
  1667. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1668. t_avg = (float)t_algo / (float)n;
  1669. printf("Called ARM cvDrawContour function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1670. gettimeofday(&startTime, NULL);
  1671. C6accel_cvDrawContours(hC6accel,inputImg2, contours,CV_RGB(255,0,0),CV_RGB(0,255,0),-1, 1,8, cvPoint(0,0) );
  1672. gettimeofday(&endTime, NULL);
  1673. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1674. t_avg = (float)t_algo / (float)n;
  1675. printf("Called DSP cvDrawContour function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1676. gettimeofday(&startTime, NULL);
  1677. cvContourArea( (void *)contours,CV_WHOLE_SEQ,0);
  1678. gettimeofday(&endTime, NULL);
  1679. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1680. t_avg = (float)t_algo / (float)n;
  1681. printf("Called ARM cvContourArea function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1682. gettimeofday(&startTime, NULL);
  1683. C6accel_cvContourArea(hC6accel, contours,CV_WHOLE_SEQ,&area );
  1684. gettimeofday(&endTime, NULL);
  1685. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1686. t_avg = (float)t_algo / (float)n;
  1687. printf("Called DSP cvContourArea function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1688. i=0;
  1689. Total_area_arm = 0.0;
  1690. Total_area_dsp = 0.0;
  1691. gettimeofday(&startTime, NULL);
  1692. for(; contours; contours = contours->h_next) {
  1693. if( contours ){
  1694. i++;
  1695. //ARM code
  1696. boundbox = cvBoundingRect(contours,1);
  1697. cvRectangle(inputImg1,
  1698. cvPoint(boundbox.x, boundbox.y),
  1699. cvPoint(boundbox.x+boundbox.width, boundbox.y+boundbox.height),
  1700. cvScalar(255,0,0,0),
  1701. 1, 8, 0);
  1702. //DSP code
  1703. //Find minimal bounding box for each sequence
  1704. C6accel_cvBoundingRect(hC6accel,contours,boundbox_ptr,1);
  1705. cvRectangle(inputImg2,
  1706. cvPoint(boundbox_ptr->x, boundbox_ptr->y),
  1707. cvPoint(boundbox_ptr->x+boundbox_ptr->width, boundbox_ptr->y+boundbox_ptr->height),
  1708. cvScalar(255,0,0,0),
  1709. 1, 8, 0);
  1710. cvDrawContours(inputImg1, contours,CV_RGB(255,0,0),CV_RGB(0,255,0),-1, 1,8, cvPoint(0,0) );
  1711. C6accel_cvDrawContours(hC6accel,inputImg2, contours,CV_RGB(255,0,0),CV_RGB(0,255,0),-1, 1,8, cvPoint(0,0) );
  1712. area_arm = fabs(cvContourArea( (void *)contours,CV_WHOLE_SEQ,0));
  1713. Total_area_arm += area_arm;
  1714. C6accel_cvContourArea(hC6accel, contours,CV_WHOLE_SEQ,&area );
  1715. Total_area_dsp += fabs(area);
  1716. }
  1717. }
  1718. gettimeofday(&endTime, NULL);
  1719. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1720. t_avg = (float)t_algo / (float)n;
  1721. printf("Called DSP Plotting function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1722. printf("Difference between total area calculated using ContourArea =%f\n", fabs(Total_area_dsp-Total_area_arm) );
  1723. // 6. Save outputs to filesystem
  1724. cvSaveImage("./output_arm_contour.png",inputImg1 , 0);
  1725. cvSaveImage("./output_dsp_contour.png",inputImg2 , 0);
  1726. //7. Free memory allocated to images
  1727. cvReleaseImage(&inputImg1);
  1728. cvReleaseImage(&g_gray);
  1729. cvReleaseImage(&inputImg2);
  1730. cvReleaseImage(&outputImg_arm);
  1731. cvReleaseImage(&outputImg_dsp);
  1732. cvReleaseMemStorage(&g_storage);
  1733. printf("Test for contours completed successfully; outputs saved to filesystem\n");
  1734. return 1;
  1735. }
  1736. Int C6Accel_test_Matchshapes(C6accel_Handle hC6accel, char *input_file_name1, char *input_file_name2,int n)
  1737. {
  1738. IplImage *inputImg1, *inputImg2, *outputImg_arm, *outputImg_dsp;
  1739. IplImage* g_gray = NULL;
  1740. double g_thresh = 100.0;
  1741. CvSeq *contour1,*contour2, *tmp1, *tmp2;
  1742. CvMemStorage* g_storage_1 = NULL;
  1743. CvMemStorage* g_storage_2 = NULL;
  1744. int status;
  1745. struct timeval startTime, endTime;
  1746. int t_overhead, t_algo, i;
  1747. float t_avg;
  1748. void *temp_ptr_1,*temp_ptr_2;
  1749. double measure,measure_arm;
  1750. unsigned int var;
  1751. // 1. Read input images from file
  1752. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1753. inputImg2 = cvLoadImage( input_file_name2, CV_LOAD_IMAGE_COLOR);
  1754. // 2. Allocate output images (must have same depth, channels as input)
  1755. // cvThreshold supports only single chanel output(8bit)
  1756. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), 8,1);
  1757. outputImg_dsp = cvCreateImage(cvSize(inputImg2->width, inputImg1->height), 8,1);
  1758. g_gray = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),8,1);
  1759. //3.Create storage for the contour
  1760. g_storage_1 = cvCreateMemStorage(0);
  1761. temp_ptr_1 = cvMemStorageAlloc(g_storage_1, 64);
  1762. contour1 = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvPoint), g_storage_1);
  1763. cvCvtColor( inputImg1, g_gray, CV_BGR2GRAY );
  1764. cvThreshold(g_gray, outputImg_arm , g_thresh, 255.0, CV_THRESH_BINARY );
  1765. cvFindContours(outputImg_arm,g_storage_1, &contour1,sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
  1766. g_storage_2 = cvCreateMemStorage(0);
  1767. temp_ptr_2 = cvMemStorageAlloc(g_storage_2, 64);
  1768. contour2 = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvPoint), g_storage_1);
  1769. cvCvtColor( inputImg2, g_gray, CV_BGR2GRAY );
  1770. cvThreshold(g_gray, outputImg_dsp , g_thresh, 255.0, CV_THRESH_BINARY );
  1771. cvFindContours(outputImg_dsp,g_storage_2, &contour2,sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
  1772. tmp1= contour1;
  1773. tmp2= contour2;
  1774. cvCopy(inputImg2,inputImg1,0);
  1775. //ARM: Benchmark loop
  1776. gettimeofday(&startTime, NULL);
  1777. for(i=0; contour1,contour2; contour1 = contour1->h_next,contour2 = contour2->h_next) {
  1778. measure_arm = cvMatchShapes(contour2,contour1, 2,1.0);
  1779. }
  1780. gettimeofday(&endTime, NULL);
  1781. //ARM: Draw loop
  1782. contour1=tmp1;
  1783. contour2=tmp2;
  1784. for(i=0; contour1,contour2; contour1 = contour1->h_next,contour2 = contour2->h_next) {
  1785. measure_arm = cvMatchShapes(contour2,contour1, 2,1.0);
  1786. //Code to plot matched and unmatched contours
  1787. printf("match_arm = %f\n",(double)measure_arm);
  1788. if(measure_arm<0.7){ //arbitary threshold
  1789. cvDrawContours(inputImg1, contour2,CV_RGB(0,255,0),CV_RGB(0,255,0),-1, 3,8, cvPoint(0,0) );
  1790. }
  1791. if(measure_arm>=0.7){//arbitary threshold
  1792. cvDrawContours(inputImg1, contour2,CV_RGB(0,0,255),CV_RGB(0,0,255),-1, 3,8, cvPoint(0,0) );
  1793. }
  1794. }
  1795. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1796. t_avg = (float)t_algo / (float)n;
  1797. printf("Called ARM cvMatchShapes function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1798. contour1=tmp1;
  1799. contour2=tmp2;
  1800. //DSP: Benchmark loop
  1801. gettimeofday(&startTime, NULL);
  1802. for(i=0; contour1,contour2; contour1 = contour1->h_next,contour2 = contour2->h_next) {
  1803. C6accel_cvMatchShapes(hC6accel,contour1,contour2, 2,1.0,&measure);
  1804. }
  1805. gettimeofday(&endTime, NULL);
  1806. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1807. t_avg = (float)t_algo / (float)n;
  1808. printf("Called DSP cvMatchShapes function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1809. contour1=tmp1;
  1810. contour2=tmp2;
  1811. //DSP: Draw loop
  1812. for(i=0; contour1,contour2; contour1 = contour1->h_next,contour2 = contour2->h_next) {
  1813. C6accel_cvMatchShapes(hC6accel,contour1,contour2, 2,1.0,&measure);
  1814. printf("match_dsp = %f\n",(double)measure);
  1815. if(measure<0.7){
  1816. cvDrawContours(inputImg2, contour2,CV_RGB(0,255,0),CV_RGB(0,255,0),-1, 3,8, cvPoint(0,0) );
  1817. }
  1818. if(measure>=0.7){
  1819. cvDrawContours(inputImg2, contour2,CV_RGB(0,0,255),CV_RGB(0,0,255),-1, 3,8, cvPoint(0,0) );
  1820. }
  1821. }
  1822. gettimeofday(&endTime, NULL);
  1823. // 6. Save outputs to filesystem
  1824. cvSaveImage("./output_arm_matchcontour.png",inputImg1 , 0);
  1825. cvSaveImage("./output_dsp_matchcontour.png",inputImg2 , 0);
  1826. //7. Free memory allocated to images
  1827. cvReleaseImage(&inputImg1);
  1828. cvReleaseImage(&inputImg2);
  1829. cvReleaseImage(&g_gray);
  1830. cvReleaseMemStorage(&g_storage_1);
  1831. cvReleaseMemStorage(&g_storage_2);
  1832. cvReleaseImage(&outputImg_arm);
  1833. cvReleaseImage(&outputImg_dsp);
  1834. return 0;
  1835. }
  1836. Int C6Accel_test_FindContours(C6accel_Handle hC6accel, char *input_file_name1, int n)
  1837. {
  1838. IplImage *inputImg1, *inputImg2, *outputImg_arm, *outputImg_dsp;
  1839. IplImage* g_gray = NULL;
  1840. double g_thresh = 100.0;
  1841. CvSeq *contour1 = NULL,*contour2=NULL , *tmp1, *tmp2;
  1842. CvMemStorage* g_storage_1 = NULL;
  1843. CvMemStorage* g_storage_2 = NULL;
  1844. int status;
  1845. struct timeval startTime, endTime;
  1846. int t_overhead, t_algo, i;
  1847. float t_avg;
  1848. void *temp_ptr_1,*temp_ptr_2;
  1849. double measure,measure_arm;
  1850. unsigned int var;
  1851. int storage_size = 200*1024; // 200K /*** Storage size from one image to other *****/
  1852. // 1. Read input images from file
  1853. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1854. printf("inp_image->imagedata= %x\n",CMEM_getPhys(inputImg1->imageData));
  1855. inputImg2 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1856. // 2. Allocate output images (must have same depth, channels as input)
  1857. // cvThreshold supports only single chanel output(8bit)
  1858. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), 8,1);
  1859. outputImg_dsp = cvCreateImage(cvSize(inputImg2->width, inputImg2->height), 8,1);
  1860. g_gray = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),8,1);
  1861. //Create storage for the contour
  1862. //ARM loop
  1863. g_storage_1 = cvCreateMemStorage(storage_size);
  1864. temp_ptr_1 = cvMemStorageAlloc(g_storage_1, 64);
  1865. cvCvtColor( inputImg1, g_gray, CV_BGR2GRAY );
  1866. cvThreshold(g_gray, outputImg_arm , g_thresh, 255.0, CV_THRESH_BINARY );
  1867. gettimeofday(&startTime, NULL);
  1868. cvFindContours(outputImg_arm,g_storage_1, &contour1,sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
  1869. gettimeofday(&endTime, NULL);
  1870. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1871. t_avg = (float)t_algo / (float)n;
  1872. printf("Called ARM cvFindContours function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1873. for(i=0;contour1;contour1=contour1->h_next,i++) {
  1874. // status = contour1->flags;
  1875. // printf("Flag=%x\n",status);
  1876. cvDrawContours(inputImg1, contour1,CV_RGB(255,0,0),CV_RGB(0,255,0),-1, 1,8, cvPoint(0,0) );
  1877. }
  1878. // printf("Press Enter\n");
  1879. // getchar();
  1880. //DSP loop
  1881. g_storage_2 = cvCreateMemStorage(storage_size);
  1882. temp_ptr_2 = cvMemStorageAlloc(g_storage_2, 64);
  1883. contour2 = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvPoint), g_storage_1);
  1884. cvCvtColor( inputImg2, g_gray, CV_BGR2GRAY );
  1885. cvThreshold(g_gray, outputImg_dsp , g_thresh, 255.0, CV_THRESH_BINARY );
  1886. gettimeofday(&startTime, NULL);
  1887. C6accel_cvFindContours(hC6accel, outputImg_dsp,g_storage_2, &contour2,sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
  1888. gettimeofday(&endTime, NULL);
  1889. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1890. t_avg = (float)t_algo / (float)n;
  1891. printf("Called DSP cvFindContours function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1892. printf("Test for cvFindContours function called successfully. Output saved to filesystem\n");
  1893. for(i=0;contour2;contour2=contour2->h_next,i++) {
  1894. // status = contour2->flags;
  1895. // printf("Flag=%x\n",status);
  1896. C6accel_cvDrawContours(hC6accel,inputImg2, contour2,CV_RGB(255,0,0),CV_RGB(0,255,0),-1, 1,8, cvPoint(0,0) );
  1897. }
  1898. // 6. Save outputs to filesystem
  1899. cvSaveImage("./output_arm_contour.png",inputImg1 , 0);
  1900. cvSaveImage("./output_dsp_contour.png",inputImg2 , 0);
  1901. //7. Free memory allocated to images
  1902. cvReleaseImage(&inputImg1);
  1903. cvReleaseImage(&inputImg2);
  1904. cvReleaseImage(&g_gray);
  1905. cvReleaseImage(&outputImg_arm);
  1906. cvReleaseImage(&outputImg_dsp);
  1907. cvReleaseMemStorage(&g_storage_2);
  1908. cvReleaseMemStorage(&g_storage_1);
  1909. return 0;
  1910. }
  1911. Int C6Accel_test_Dilate(C6accel_Handle hC6accel, char *input_file_name1, int n)
  1912. {
  1913. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp;
  1914. int pos= 0;
  1915. struct timeval startTime, endTime;
  1916. int t_overhead, t_algo, i;
  1917. float t_avg;
  1918. // 1. Load Input
  1919. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1920. // 2. Allocate output images (must have same depth, channels as input)
  1921. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1922. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1923. //3. Benchmark the ARM call
  1924. gettimeofday(&startTime, NULL);
  1925. for (i = 0; i < n; i++)
  1926. cvDilate(inputImg1,outputImg_arm,NULL,pos);
  1927. gettimeofday(&endTime, NULL);
  1928. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1929. t_avg = (float)t_algo / (float)n;
  1930. printf("Called ARM cvDilate function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1931. //4. Benchmark the DSP call
  1932. gettimeofday(&startTime, NULL);
  1933. for (i = 0; i < n; i++)
  1934. C6accel_cvDilate(hC6accel,inputImg1,outputImg_dsp,NULL,pos);
  1935. gettimeofday(&endTime, NULL);
  1936. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1937. t_avg = (float)t_algo / (float)n;
  1938. printf("Called DSP cvDilate function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1939. // 5. Compare outputs
  1940. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  1941. // 6. Save output
  1942. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  1943. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  1944. printf("Test for Dilate operations done\n");
  1945. //7. Free memory allocated to images
  1946. cvReleaseImage(&inputImg1);
  1947. cvReleaseImage(&outputImg_arm);
  1948. cvReleaseImage(&outputImg_dsp);
  1949. return 1;
  1950. }
  1951. Int C6Accel_test_Erode(C6accel_Handle hC6accel, char *input_file_name1, int n)
  1952. {
  1953. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp;
  1954. int pos= 0;
  1955. struct timeval startTime, endTime;
  1956. int t_overhead, t_algo, i;
  1957. float t_avg;
  1958. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1959. // 2. Allocate output images (must have same depth, channels as input)
  1960. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1961. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  1962. gettimeofday(&startTime, NULL);
  1963. for (i = 0; i < n; i++)
  1964. cvErode(inputImg1,outputImg_arm,NULL,pos);
  1965. gettimeofday(&endTime, NULL);
  1966. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1967. t_avg = (float)t_algo / (float)n;
  1968. printf("Called ARM cvErode function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1969. gettimeofday(&startTime, NULL);
  1970. for (i = 0; i < n; i++)
  1971. C6accel_cvErode(hC6accel,inputImg1,outputImg_dsp,NULL,pos);
  1972. gettimeofday(&endTime, NULL);
  1973. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  1974. t_avg = (float)t_algo / (float)n;
  1975. printf("Called DSP cvErode function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  1976. // 5. Compare outputs
  1977. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  1978. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  1979. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  1980. printf("Test for Erode operations done\n");
  1981. //7. Free memory allocated to images
  1982. cvReleaseImage(&inputImg1);
  1983. cvReleaseImage(&outputImg_arm);
  1984. cvReleaseImage(&outputImg_dsp);
  1985. return 1;
  1986. }
  1987. Int C6Accel_test_Laplace(C6accel_Handle hC6accel, char *input_file_name1, int n)
  1988. {
  1989. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp, *g_gray;
  1990. int pos= 0;
  1991. struct timeval startTime, endTime;
  1992. int t_overhead, t_algo, i;
  1993. float t_avg;
  1994. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  1995. // 2. Allocate output images (must have same depth, channels as input)
  1996. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), IPL_DEPTH_16S, 1);
  1997. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), IPL_DEPTH_16S, 1);
  1998. g_gray = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),IPL_DEPTH_8U, 1);
  1999. cvCvtColor( inputImg1, g_gray, CV_BGR2GRAY );
  2000. gettimeofday(&startTime, NULL);
  2001. //for (i = 0; i < n; i++)
  2002. cvLaplace(g_gray,outputImg_arm ,3);
  2003. gettimeofday(&endTime, NULL);
  2004. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2005. t_avg = (float)t_algo / (float)n;
  2006. printf("Called ARM cvLaplace function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2007. gettimeofday(&startTime, NULL);
  2008. // for (i = 0; i < n; i++)
  2009. C6accel_cvLaplace(hC6accel,g_gray,outputImg_dsp,3);
  2010. gettimeofday(&endTime, NULL);
  2011. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2012. t_avg = (float)t_algo /(float)n;
  2013. printf("Called DSP cvLaplace function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2014. // 5. Compare outputs
  2015. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2016. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  2017. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  2018. printf("Test for Laplace operations done\n");
  2019. //7. Free memory allocated to images
  2020. cvReleaseImage(&inputImg1);
  2021. cvReleaseImage(&g_gray);
  2022. cvReleaseImage(&outputImg_arm);
  2023. cvReleaseImage(&outputImg_dsp);
  2024. return 1;
  2025. }
  2026. Int C6Accel_test_PyrDown(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2027. {
  2028. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp;
  2029. int pos= 0;
  2030. struct timeval startTime, endTime;
  2031. int t_overhead, t_algo, i;
  2032. float t_avg;
  2033. inputImg1 = cvLoadImage( input_file_name1, 0);
  2034. // 2. Allocate output images (must have same depth, channels as input)
  2035. outputImg_arm = cvCreateImage(cvSize(inputImg1->width/2, inputImg1->height/2), IPL_DEPTH_8U, 1);
  2036. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width/2, inputImg1->height/2), IPL_DEPTH_8U, 1);
  2037. gettimeofday(&startTime, NULL);
  2038. for (i = 0; i < n; i++)
  2039. cvPyrDown(inputImg1,outputImg_arm ,CV_GAUSSIAN_5x5);
  2040. gettimeofday(&endTime, NULL);
  2041. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2042. t_avg = (float)t_algo / (float)n;
  2043. printf("Called ARM cvPyrDown function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2044. gettimeofday(&startTime, NULL);
  2045. for (i = 0; i < n; i++)
  2046. C6accel_cvPyrDown(hC6accel,inputImg1,outputImg_dsp,CV_GAUSSIAN_5x5);
  2047. gettimeofday(&endTime, NULL);
  2048. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2049. t_avg = (float)t_algo / (float)n;
  2050. printf("Called DSP cvPyrDown function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2051. // 5. Compare outputs
  2052. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2053. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  2054. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  2055. printf("Test for PyrDown operations done\n");
  2056. //7. Free memory allocated to images
  2057. cvReleaseImage(&inputImg1);
  2058. cvReleaseImage(&outputImg_arm);
  2059. cvReleaseImage(&outputImg_dsp);
  2060. return 1;
  2061. }
  2062. Int C6Accel_test_Filter2D(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2063. {
  2064. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp;
  2065. int pos= 0;
  2066. struct timeval startTime, endTime;
  2067. int t_overhead, t_algo, i;
  2068. float t_avg;
  2069. CvMat *filter;
  2070. int nFiltCols=5, nFiltRows =5;
  2071. float kernel [25] = { 0,-1, 0,1,0,
  2072. -1,-2,0,2,1,
  2073. -1,-2,1,2,1,
  2074. -1,-1,0,2,1,
  2075. 0,-1,0,1,0};
  2076. float* pkernel;
  2077. /* Allocate CMEM memory for 3x3 short mask*/
  2078. pkernel = Memory_alloc(25*sizeof(float), &testfxnsMemParams);
  2079. memcpy( pkernel,kernel,25*sizeof(float));
  2080. inputImg1 = cvLoadImage( input_file_name1, 0);
  2081. // 2. Allocate output images (must have same depth, channels as input)
  2082. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), IPL_DEPTH_8U, 1);
  2083. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), IPL_DEPTH_8U, 1);
  2084. filter = cvCreateMat(nFiltRows, nFiltCols, CV_32FC1);
  2085. cvSetData(filter,pkernel,nFiltCols*sizeof(float) );
  2086. printf("Mat =%x\n", CMEM_getPhys(filter));
  2087. gettimeofday(&startTime, NULL);
  2088. for (i = 0; i < n; i++)
  2089. cvFilter2D(inputImg1,outputImg_arm,filter,cvPoint(-1,-1));
  2090. gettimeofday(&endTime, NULL);
  2091. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2092. t_avg = (float)t_algo / (float)n;
  2093. printf("Called ARM cvFilter2D function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2094. gettimeofday(&startTime, NULL);
  2095. for (i = 0; i < n; i++)
  2096. C6accel_cvFilter2D(hC6accel,inputImg1,outputImg_dsp,filter,cvPoint(-1,-1));
  2097. gettimeofday(&endTime, NULL);
  2098. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2099. t_avg = (float)t_algo / (float)n;
  2100. printf("Called DSP cvFilter2D function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2101. // 5. Compare outputs
  2102. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2103. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  2104. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  2105. printf("Test for Filter2D operations done\n");
  2106. //7. Free memory allocated to images
  2107. cvReleaseImage(&inputImg1);
  2108. cvReleaseImage(&outputImg_arm);
  2109. cvReleaseImage(&outputImg_dsp);
  2110. //printf("Test for Filter2D operations done\n");
  2111. /* Release Gaussian CMEM */
  2112. Memory_free(pkernel,25*sizeof(float),&testfxnsMemParams);
  2113. return 1;
  2114. }
  2115. Int C6Accel_test_Canny(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2116. {
  2117. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp, *g_gray;
  2118. int pos= 0;
  2119. struct timeval startTime, endTime;
  2120. int t_overhead, t_algo, i;
  2121. float t_avg;
  2122. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  2123. // 2. Allocate output images (must have same depth, channels as input)
  2124. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), 8,1);
  2125. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), 8,1);
  2126. g_gray = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),8,1);
  2127. //for (i=0;i<30;i++)
  2128. cvCvtColor(inputImg1, g_gray, CV_BGR2GRAY );
  2129. gettimeofday(&startTime, NULL);
  2130. for (i = 0; i < n; i++)
  2131. cvCanny(g_gray,outputImg_arm ,10.0,100.0,3);
  2132. gettimeofday(&endTime, NULL);
  2133. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2134. t_avg = (float)t_algo / (float)n;
  2135. printf("Called ARM cvCanny function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2136. gettimeofday(&startTime, NULL);
  2137. for (i = 0; i < n; i++)
  2138. C6accel_cvCanny(hC6accel,g_gray,outputImg_dsp,(double)10.0,(double)100.00,3);
  2139. gettimeofday(&endTime, NULL);
  2140. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2141. t_avg = (float)t_algo / (float)n;
  2142. printf("Called DSP cvCanny function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2143. // 5. Compare outputs
  2144. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2145. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  2146. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  2147. printf("Test for Canny edge detection done\n");
  2148. //7. Free memory allocated to images
  2149. cvReleaseImage(&inputImg1);
  2150. cvReleaseImage(&g_gray);
  2151. cvReleaseImage(&outputImg_arm);
  2152. cvReleaseImage(&outputImg_dsp);
  2153. return 1;
  2154. }
  2155. Int C6Accel_test_CornerHarris(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2156. {
  2157. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp, *corner8;
  2158. int pos= 0;
  2159. struct timeval startTime, endTime;
  2160. int t_overhead, t_algo, i;
  2161. float t_avg;
  2162. double minVal=0.0, maxVal=0.0;
  2163. double scale, shift;
  2164. double min=0, max=255;
  2165. inputImg1 = cvLoadImage( input_file_name1, 0);
  2166. // 2. Allocate output images (must have same depth, channels as input)
  2167. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),IPL_DEPTH_32F ,1);
  2168. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), IPL_DEPTH_32F ,1);
  2169. corner8 = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),IPL_DEPTH_8U ,1);
  2170. gettimeofday(&startTime, NULL);
  2171. for (i = 0; i < n; i++)
  2172. cvCornerHarris(inputImg1,outputImg_arm ,3,3, 0.04);
  2173. gettimeofday(&endTime, NULL);
  2174. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2175. t_avg = (float)t_algo / (float)n;
  2176. printf("Called ARM cvCornerHarris function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2177. cvMinMaxLoc( outputImg_arm, &minVal, &maxVal, NULL, NULL, 0);
  2178. scale = (max - min)/(maxVal-minVal);
  2179. shift = -minVal * scale + min;
  2180. cvConvertScale(outputImg_arm, corner8 ,scale,shift);
  2181. cvSaveImage("./output_arm.png",corner8 , 0);
  2182. gettimeofday(&startTime, NULL);
  2183. for (i = 0; i < n; i++)
  2184. C6accel_cvCornerHarris(hC6accel,inputImg1,outputImg_dsp,3,3, 0.04);
  2185. gettimeofday(&endTime, NULL);
  2186. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2187. t_avg = (float)t_algo / (float)n;
  2188. printf("Called DSP cvCornerHarris function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2189. cvMinMaxLoc( outputImg_dsp, &minVal, &maxVal, NULL, NULL, 0);
  2190. scale = (max - min)/(maxVal-minVal);
  2191. shift = -minVal * scale + min;
  2192. cvConvertScale(outputImg_dsp, corner8 ,scale,shift);
  2193. // 5. Compare outputs
  2194. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2195. cvSaveImage("./output_dsp.png",corner8 , 0);
  2196. printf("Test for cornerharris edge detection done\n");
  2197. //7. Free memory allocated to images
  2198. cvReleaseImage(&inputImg1);
  2199. cvReleaseImage(&corner8);
  2200. cvReleaseImage(&outputImg_arm);
  2201. cvReleaseImage(&outputImg_dsp);
  2202. return 1;
  2203. }
  2204. Int C6Accel_test_CornerEigenValsAndVecs(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2205. {
  2206. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp, *g_gray, *eig_val_arm, *eig_val_dsp;
  2207. int pos= 0;
  2208. struct timeval startTime, endTime;
  2209. int t_overhead, t_algo, i;
  2210. float t_avg;
  2211. double minVal=0.0, maxVal=0.0;
  2212. double scale, shift;
  2213. double min=0, max=255;
  2214. inputImg1 = cvLoadImage( input_file_name1, 1);
  2215. // 2. Allocate output images (must have same depth, channels as input)
  2216. //Output must have 6 times the width of the input image to store Eigen values and eigen vectors.
  2217. outputImg_arm = cvCreateImage(cvSize(inputImg1->width*6, inputImg1->height),IPL_DEPTH_32F ,1);
  2218. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width*6, inputImg1->height), IPL_DEPTH_32F ,1);
  2219. g_gray = cvCreateImage(cvSize(inputImg1->width,inputImg1->height), inputImg1->depth, 1);
  2220. eig_val_arm = cvCreateImage(cvSize(inputImg1->width,inputImg1->height), IPL_DEPTH_32F, 1);
  2221. eig_val_dsp = cvCreateImage(cvSize(inputImg1->width,inputImg1->height), IPL_DEPTH_32F, 1);
  2222. cvvConvertImage (inputImg1, g_gray, 0);
  2223. gettimeofday(&startTime, NULL);
  2224. //After that it finds eigenvectors and eigenvalues of
  2225. //the resultant matrix and stores them into destination
  2226. //image in form (¦Ë1, ¦Ë2, x1, y1, x2, y2), where
  2227. //¦Ë1, ¦Ë2 - eigenvalues of M; not sorted
  2228. //(x1, y1) - eigenvector corresponding to ¦Ë1
  2229. //(x2, y2) - eigenvector corresponding to ¦Ë2
  2230. for (i = 0; i < n; i++)
  2231. cvCornerEigenValsAndVecs(g_gray,outputImg_arm ,5,5);
  2232. gettimeofday(&endTime, NULL);
  2233. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2234. t_avg = (float)t_algo / (float)n;
  2235. printf("Called ARM cvCornerEigenValsAndVecs function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2236. // cvSaveImage("./output_arm.png",outputImg_arm , 0);
  2237. gettimeofday(&startTime, NULL);
  2238. for (i = 0; i < n; i++)
  2239. C6accel_cvCornerEigenValsAndVecs(hC6accel,g_gray,outputImg_dsp,5,5);
  2240. gettimeofday(&endTime, NULL);
  2241. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2242. t_avg = (float)t_algo / (float)n;
  2243. printf("Called DSP cvCornerEigenValsAndVecs function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2244. // 5. Compare outputs
  2245. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2246. gettimeofday(&startTime, NULL);
  2247. for (i = 0; i < n; i++)
  2248. cvCornerMinEigenVal(g_gray,eig_val_arm ,5,5);
  2249. gettimeofday(&endTime, NULL);
  2250. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2251. t_avg = (float)t_algo / (float)n;
  2252. printf("Called ARM cvCornerMinEigenVal function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2253. cvSaveImage("./output_arm.png",eig_val_arm , 0);
  2254. gettimeofday(&startTime, NULL);
  2255. for (i = 0; i < n; i++)
  2256. C6accel_cvCornerMinEigenVal(hC6accel,g_gray,eig_val_dsp ,5,5);
  2257. gettimeofday(&endTime, NULL);
  2258. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2259. t_avg = (float)t_algo / (float)n;
  2260. printf("Called DSP cvCornerMinEigenVal function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2261. cvSaveImage("./output_dsp.png",eig_val_dsp , 0);
  2262. // 5. Compare outputs
  2263. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(eig_val_arm, eig_val_dsp, CV_L2, NULL));
  2264. printf("Test for CornerEigenValsAndVecs and CornerMinEigVal completed successfully\n");
  2265. //7. Free memory allocated to images
  2266. cvReleaseImage(&inputImg1);
  2267. cvReleaseImage(&g_gray);
  2268. cvReleaseImage(&eig_val_arm);
  2269. cvReleaseImage(&eig_val_dsp);
  2270. cvReleaseImage(&outputImg_arm);
  2271. cvReleaseImage(&outputImg_dsp);
  2272. return 1;
  2273. }
  2274. Int C6Accel_test_Smooth(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2275. {
  2276. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp, *g_gray;
  2277. int pos= 0;
  2278. struct timeval startTime, endTime;
  2279. int t_overhead, t_algo, i;
  2280. float t_avg;
  2281. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  2282. // 2. Allocate output images (must have same depth, channels as input)
  2283. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  2284. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), inputImg1->depth, inputImg1->nChannels);
  2285. gettimeofday(&startTime, NULL);
  2286. for (i = 0; i < n; i++)
  2287. cvSmooth(inputImg1,outputImg_arm ,CV_GAUSSIAN, 11,11,0.0,0.0);
  2288. gettimeofday(&endTime, NULL);
  2289. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2290. t_avg = (float)t_algo / (float)n;
  2291. printf("Called ARM cvSmooth function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2292. gettimeofday(&startTime, NULL);
  2293. for (i = 0; i < n; i++)
  2294. C6accel_cvSmooth(hC6accel,inputImg1,outputImg_dsp ,CV_GAUSSIAN, 11,11,(double)0.0,(double)0.0);
  2295. gettimeofday(&endTime, NULL);
  2296. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2297. t_avg = (float)t_algo / (float)n;
  2298. printf("Called DSP cvSmooth function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2299. // 5. Compare outputs
  2300. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2301. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  2302. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  2303. printf("Test for Smooth/Bluring operation done\n");
  2304. //7. Free memory allocated to images
  2305. cvReleaseImage(&inputImg1);
  2306. cvReleaseImage(&outputImg_arm);
  2307. cvReleaseImage(&outputImg_dsp);
  2308. return 1;
  2309. }
  2310. Int C6Accel_test_AdaptiveThreshold(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2311. {
  2312. IplImage *inputImg1, *outputImg_arm, *outputImg_dsp, *g_gray;
  2313. int pos= 0;
  2314. struct timeval startTime, endTime;
  2315. int t_overhead, t_algo, i;
  2316. float t_avg;
  2317. inputImg1 = cvLoadImage( input_file_name1, CV_LOAD_IMAGE_COLOR);
  2318. // 2. Allocate output images (must have same depth, channels as input)
  2319. outputImg_arm = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), IPL_DEPTH_8U,1);
  2320. outputImg_dsp = cvCreateImage(cvSize(inputImg1->width, inputImg1->height), IPL_DEPTH_8U,1);
  2321. g_gray = cvCreateImage(cvSize(inputImg1->width, inputImg1->height),IPL_DEPTH_8U,1);
  2322. cvCvtColor( inputImg1, g_gray, CV_BGR2GRAY );
  2323. gettimeofday(&startTime, NULL);
  2324. for (i = 0; i < n; i++)
  2325. cvAdaptiveThreshold(g_gray,outputImg_arm ,(double)125.0, CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY,7,(double)10.0);
  2326. gettimeofday(&endTime, NULL);
  2327. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2328. t_avg = (float)t_algo / (float)n;
  2329. printf("Called ARM Adaptive threshold function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2330. cvCvtColor( inputImg1, g_gray, CV_BGR2GRAY );
  2331. gettimeofday(&startTime, NULL);
  2332. for (i = 0; i < n; i++)
  2333. C6accel_cvAdaptiveThreshold(hC6accel,g_gray,outputImg_dsp ,(double)125.0, CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY,7,(double)10.0);
  2334. gettimeofday(&endTime, NULL);
  2335. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2336. t_avg = (float)t_algo / (float)n;
  2337. printf("Called DSP Adaptive threshold function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2338. // 5. Compare outputs
  2339. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(outputImg_arm, outputImg_dsp, CV_L2, NULL));
  2340. cvSaveImage("./output_arm.png",outputImg_arm , 0);
  2341. cvSaveImage("./output_dsp.png",outputImg_dsp , 0);
  2342. printf("Test for Adaptive thresholding operation done\n");
  2343. //7. Free memory allocated to images
  2344. cvReleaseImage(&inputImg1);
  2345. cvReleaseImage(&g_gray);
  2346. cvReleaseImage(&outputImg_arm);
  2347. cvReleaseImage(&outputImg_dsp);
  2348. return 1;
  2349. }
  2350. Int C6Accel_test_Houghlines2D(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2351. {
  2352. IplImage* src, *dst;
  2353. IplImage* color_dst_arm, *color_dst_dsp;
  2354. CvMemStorage* storage_dsp, *storage_arm ;
  2355. CvSeq* lines_dsp = NULL, *lines_arm =NULL;
  2356. int t_overhead, t_algo, i;
  2357. struct timeval startTime, endTime;
  2358. float t_avg;
  2359. CvPoint pt1,pt2;
  2360. float* line, rho, theta;
  2361. double a,b, x0,y0;
  2362. void *temp_ptr;
  2363. src= cvLoadImage(input_file_name1, 0);
  2364. dst= cvCreateImage( cvGetSize(src), 8, 1 );
  2365. color_dst_arm = cvCreateImage( cvGetSize(src), 8, 3 );
  2366. color_dst_dsp = cvCreateImage( cvGetSize(src), 8, 3 );
  2367. storage_arm = cvCreateMemStorage(0);
  2368. temp_ptr = cvMemStorageAlloc(storage_arm, 64);
  2369. cvCanny( src, dst, 50, 200, 3 );
  2370. cvCvtColor( dst, color_dst_arm, CV_GRAY2BGR );
  2371. cvCvtColor( dst, color_dst_dsp, CV_GRAY2BGR );
  2372. gettimeofday(&startTime, NULL);
  2373. /*C6accel_cvHoughLines2( hC6accel, dst,
  2374. storage,
  2375. CV_HOUGH_PROBABILISTIC,
  2376. (double)1.0,
  2377. (double)(CV_PI/180),
  2378. 80,
  2379. (double)30.0,
  2380. (double)10.0,&lines );*/
  2381. lines_arm = cvHoughLines2( dst,
  2382. storage_arm,
  2383. CV_HOUGH_PROBABILISTIC,
  2384. (double)1.0,
  2385. (double)(CV_PI/180),
  2386. 80,
  2387. (double)30.0,
  2388. (double)10.0);
  2389. gettimeofday(&endTime, NULL);
  2390. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2391. t_avg = (float)t_algo / (float)n;
  2392. printf("Called ARM HoughLines2D function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2393. for( i = 0; i < lines_arm->total; i++ )
  2394. {
  2395. CvPoint* line = (CvPoint*)cvGetSeqElem(lines_arm,i);
  2396. cvLine( color_dst_arm, line[0], line[1], CV_RGB(255,0,0), 1, 8,0 );
  2397. }
  2398. cvSaveImage("./output_arm.png",color_dst_arm , 0);
  2399. //DSP Processing
  2400. storage_dsp = cvCreateMemStorage(0);
  2401. temp_ptr = cvMemStorageAlloc(storage_dsp, 64);
  2402. gettimeofday(&startTime, NULL);
  2403. C6accel_cvHoughLines2( hC6accel, dst,
  2404. storage_dsp,
  2405. CV_HOUGH_PROBABILISTIC,
  2406. (double)1.0,
  2407. (double)(CV_PI/180),
  2408. 80,
  2409. (double)30.0,
  2410. (double)10.0,&lines_dsp );
  2411. gettimeofday(&endTime, NULL);
  2412. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2413. t_avg = (float)t_algo / (float)n;
  2414. printf("Called DSP HoughLines2D function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2415. for( i = 0; i < lines_dsp->total; i++ )
  2416. {
  2417. CvPoint* line = (CvPoint*)cvGetSeqElem(lines_dsp,i);
  2418. cvLine( color_dst_dsp, line[0], line[1], CV_RGB(255,0,0), 1, 8,0 );
  2419. }
  2420. // 5. Compare outputs
  2421. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(color_dst_arm, color_dst_dsp, CV_L2, NULL));
  2422. cvSaveImage("./output_dsp.png",color_dst_dsp , 0);
  2423. printf("Releasing allocated buffers\n");
  2424. //6 Release Memory allocatted for the test
  2425. cvReleaseImage( &color_dst_arm );
  2426. cvReleaseImage( &color_dst_dsp );
  2427. cvReleaseImage( &src);
  2428. cvReleaseImage( &dst);
  2429. cvReleaseMemStorage( &storage_arm);
  2430. cvReleaseMemStorage( &storage_dsp);
  2431. return 1;
  2432. }
  2433. /*Int C6Accel_test_opticalflowHS(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2434. {
  2435. int step, x,y;
  2436. float *px, *py;
  2437. int t_overhead, t_algo, i;
  2438. struct timeval startTime, endTime;
  2439. float t_avg;
  2440. // Initialize, load two images from the file system, and
  2441. // allocate the images and other structures we will need for
  2442. // results.
  2443. // exit if no input images
  2444. IplImage *imgA = 0, *imgB = 0;
  2445. imgA = cvLoadImage("opencv_images/OpticalFlow0.jpg",0);
  2446. imgB = cvLoadImage("opencv_images/OpticalFlow1.jpg",0);
  2447. if(!(imgA)||!(imgB)){ printf("One of OpticalFlow0.jpg and/or OpticalFlow1.jpg didn't load\n"); return -1;}
  2448. printf("1\n");
  2449. IplImage* velx = cvCreateImage(cvGetSize(imgA),IPL_DEPTH_32F,1);
  2450. IplImage* vely = cvCreateImage(cvGetSize(imgA),IPL_DEPTH_32F,1);
  2451. IplImage* imgC = cvCreateImage(cvGetSize(imgA),IPL_DEPTH_8U,3);
  2452. imgC = cvLoadImage("opencv_images/OpticalFlow1.jpg",1);
  2453. printf("2\n");
  2454. cvSaveImage( "./OpticalFlow0.png",imgA, 0 );
  2455. cvSaveImage( "./OpticalFlow1.png",imgB, 0 );
  2456. gettimeofday(&startTime, NULL);
  2457. // Call the actual Horn and Schunck algorithm
  2458. //
  2459. cvCalcOpticalFlowHS(
  2460. imgA,
  2461. imgB,
  2462. 0,
  2463. velx,
  2464. vely,
  2465. .10,
  2466. cvTermCriteria(
  2467. CV_TERMCRIT_ITER | CV_TERMCRIT_EPS,
  2468. imgA->width,
  2469. 1e-6
  2470. )
  2471. );
  2472. gettimeofday(&endTime, NULL);
  2473. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2474. t_avg = (float)t_algo / (float)n;
  2475. printf("Called Optical flow function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2476. // Now make some image of what we are looking at:
  2477. //
  2478. gettimeofday(&startTime, NULL);
  2479. step = 4;
  2480. for( y=0; y<imgC->height; y += step ) {
  2481. px = (float*) ( velx->imageData + y * velx->widthStep );
  2482. py = (float*) ( vely->imageData + y * vely->widthStep );
  2483. for( x=0; x<imgC->width; x += step ) {
  2484. if( px[x]>1 && py[x]>1 ) {
  2485. cvCircle(
  2486. imgC,
  2487. cvPoint( x, y ),
  2488. 2,
  2489. CVX_GRAY50,
  2490. -1,8,0
  2491. );
  2492. cvLine(
  2493. imgC,
  2494. cvPoint( x, y ),
  2495. cvPoint( x+px[x]/2, y+py[x]/2 ),
  2496. CV_RGB(255,0,0),
  2497. 1,8,
  2498. 0
  2499. );
  2500. }
  2501. }
  2502. }
  2503. gettimeofday(&endTime, NULL);
  2504. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2505. t_avg = (float)t_algo / (float)n;
  2506. printf("Called ARM cvSmooth function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2507. // show tracking
  2508. cvSaveImage( "./Flow Results.png",imgC ,0);
  2509. // release memory
  2510. cvReleaseImage( &imgA );
  2511. cvReleaseImage( &imgB );
  2512. cvReleaseImage( &imgC );
  2513. cvReleaseImage( &velx);
  2514. cvReleaseImage( &vely);
  2515. return 0;
  2516. }*/
  2517. Int C6Accel_test_rotation(C6accel_Handle hC6accel, char *input_file_name1, int n)
  2518. {
  2519. int angle_switch_value = 0;
  2520. int angleInt = 0;
  2521. int scale_switch_value = 0;
  2522. int scaleInt = 0;
  2523. struct timeval startTime, endTime;
  2524. int t_overhead, t_algo, i;
  2525. float t_avg;
  2526. // Set up variables
  2527. CvPoint2D32f srcTri[3], dstTri[3];
  2528. CvMat* rot_mat = cvCreateMat(2,3,CV_32FC1);
  2529. CvMat* rot_mat_dsp = cvCreateMat(2,3,CV_32FC1);
  2530. CvMat* warp_mat = cvCreateMat(2,3,CV_32FC1);
  2531. CvMat* warp_mat_dsp = cvCreateMat(2,3,CV_32FC1);
  2532. IplImage *src, *dst_arm, *dst_dsp;
  2533. const char* name = "Affine_Transform";
  2534. // Load image
  2535. src=cvLoadImage(input_file_name1,1);
  2536. dst_arm = cvLoadImage(input_file_name1,1);
  2537. dst_dsp = cvLoadImage(input_file_name1,1);
  2538. dst_arm->origin = src->origin;
  2539. dst_dsp->origin = src->origin;
  2540. cvZero( dst_arm );
  2541. cvZero( dst_dsp );
  2542. // Create angle and scale
  2543. double angle = 45.0;
  2544. double scale = 1.0;
  2545. // Compute warp matrix
  2546. srcTri[0].x = 0;
  2547. srcTri[0].y = 0;
  2548. srcTri[1].x = src->width - 1;
  2549. srcTri[1].y = 0;
  2550. srcTri[2].x = 0;
  2551. srcTri[2].y = src->height - 1;
  2552. dstTri[0].x = src->width*0.0;
  2553. dstTri[0].y = src->height*0.25;
  2554. dstTri[1].x = src->width*0.90;
  2555. dstTri[1].y = src->height*0.15;
  2556. dstTri[2].x = src->width*0.10;
  2557. dstTri[2].y = src->height*0.75;
  2558. gettimeofday(&startTime, NULL);
  2559. cvGetAffineTransform( srcTri, dstTri, warp_mat );
  2560. gettimeofday(&endTime, NULL);
  2561. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2562. t_avg = (float)t_algo / (float)n;
  2563. printf("Called ARM get Affine transform matrix %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2564. gettimeofday(&startTime, NULL);
  2565. C6accel_cvGetAffineTransform( hC6accel, srcTri, dstTri, warp_mat_dsp );
  2566. gettimeofday(&endTime, NULL);
  2567. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2568. t_avg = (float)t_algo / (float)n;
  2569. printf("Called DSP get Affine transform matrix %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2570. // 5. Compare outputs
  2571. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(warp_mat, warp_mat_dsp, CV_L2, NULL));
  2572. gettimeofday(&startTime, NULL);
  2573. cvWarpAffine( src, dst_arm, warp_mat,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,cvScalarAll(0) );
  2574. gettimeofday(&endTime, NULL);
  2575. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2576. t_avg = (float)t_algo / (float)n;
  2577. printf("Called ARM Affine transform function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2578. gettimeofday(&startTime, NULL);
  2579. C6accel_cvWarpAffine( hC6accel,src, dst_dsp, warp_mat_dsp,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,cvScalarAll(0) );
  2580. gettimeofday(&endTime, NULL);
  2581. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2582. t_avg = (float)t_algo / (float)n;
  2583. printf("Called DSP Affine transform function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2584. // 5. Compare outputs
  2585. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(dst_arm, dst_dsp, CV_L2, NULL));
  2586. cvSaveImage( "./output_arm_affine.png",dst_arm ,0);
  2587. cvSaveImage( "./output_dsp_affine.png",dst_dsp ,0);
  2588. cvCopy ( dst_arm, src, NULL );
  2589. cvCopy ( dst_dsp, src, NULL );
  2590. // Compute rotation matrix
  2591. CvPoint2D32f center = cvPoint2D32f( src->width/2, src->height/2 );
  2592. gettimeofday(&startTime, NULL);
  2593. cv2DRotationMatrix(center, angle, scale, rot_mat );
  2594. gettimeofday(&endTime, NULL);
  2595. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2596. t_avg = (float)t_algo / (float)n;
  2597. printf("Called ARM 2D Rotation Matrix function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2598. gettimeofday(&startTime, NULL);
  2599. C6accel_cv2DRotationMatrix(hC6accel, center, angle, scale, rot_mat_dsp );
  2600. gettimeofday(&endTime, NULL);
  2601. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2602. t_avg = (float)t_algo / (float)n;
  2603. printf("Called DSP 2D Rotation Matrix function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2604. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(rot_mat, rot_mat_dsp, CV_L2, NULL));
  2605. // Do the transformation
  2606. gettimeofday(&startTime, NULL);
  2607. cvWarpAffine(src, dst_arm, rot_mat,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,cvScalarAll(0) );
  2608. gettimeofday(&endTime, NULL);
  2609. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2610. t_avg = (float)t_algo / (float)n;
  2611. printf("Called ARM Rotation using Affine function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2612. // Do the transformation
  2613. gettimeofday(&startTime, NULL);
  2614. C6accel_cvWarpAffine( hC6accel,src, dst_dsp, rot_mat,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,cvScalarAll(0) );
  2615. gettimeofday(&endTime, NULL);
  2616. t_algo = (endTime.tv_sec - startTime.tv_sec) * 1000000 + endTime.tv_usec - startTime.tv_usec - t_overhead;
  2617. t_avg = (float)t_algo / (float)n;
  2618. printf("Called DSP Rotation using Affine function %i times (average time: %f ms)\n", n, t_avg / 1000.0);
  2619. // 5. Compare outputs
  2620. printf("Difference (L2 norm) between ARM and DSP outputs: %f\n", cvNorm(dst_arm, dst_dsp, CV_L2, NULL));
  2621. cvSaveImage( "./output_arm_rotated.png",dst_arm ,0);
  2622. cvSaveImage( "./output_dsp_rotated.png",dst_dsp ,0);
  2623. cvReleaseImage( &dst_arm );
  2624. cvReleaseImage( &dst_dsp );
  2625. cvReleaseImage( &src);
  2626. cvReleaseMat( &rot_mat );
  2627. cvReleaseMat( &warp_mat );
  2628. cvReleaseMat( &rot_mat_dsp );
  2629. cvReleaseMat( &warp_mat_dsp );
  2630. return 0;
  2631. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/882490
推荐阅读
相关标签
  

闽ICP备14008679号