4、host端程序代码
Host端程序处理流程就是按照前面“程序设计”一节编写的。除了调用OpenCL+OpenCV的API函数,其他的地方都是按照C/C++语法编写的。
具体代码如下:
1. // ImageRotate.cpp : 定义控制台应用程序的入口点。
2. //
3.
4. #include "stdafx.h"
5. #include <iostream>
6. #include <fstream>
7. #include <sstream>
8.
9. #include <opencv2/opencv.hpp>
10.
11. #ifdef __APPLE__
12. #include <OpenCL/cl.h>
13. #else
14. #include <CL/cl.h>
15. #endif
16.
17. using namespace cv;
18.
19. int _tmain(int argc, _TCHAR* argv[])
20. {
21. cl_int ciErrNum;
22. const char *fileName = "ImageRotate.cl";
23. int width = 0, height = 0;
24. float cos_theta = 0.7071067811865476, sin_theta = 0.7071067811865475; //for degree 45
25. //float cos_theta = 0.5, sin_theta = 0.5;
26. const char* imageName = "F:\\code\\pic\\test01.jpg";
27. char *bufInput = NULL, *bufOutput = NULL;
28.
29.
30. //read one jpeg pic and store it in a Mat variable.
31. Mat img = imread(imageName);
32. if (!img.data) {
33. std::cout << "fail to open the file:" << imageName << std::endl;
34. }
35.
36. //the type of img is RGB, convert to gray image.
37. Mat imgGray;
38. cvtColor(img, imgGray, CV_BGR2GRAY);
39. width = imgGray.cols;
40. height = imgGray.rows;
41. std::cout << "picture width: " << width << ", height: " << height << std::endl;
42.
43. //save the source data of original gray image.
44. FILE *yuvFileOrg = NULL;
45. fopen_s(&yuvFileOrg, "gray_org.yuv", "wb");
46. fwrite(imgGray.data, width * height * sizeof(unsigned char), 1, yuvFileOrg);
47. fclose(yuvFileOrg);
48. yuvFileOrg = NULL;
49.
50. //display the original gray image in a window.
51. namedWindow( imageName, CV_WINDOW_AUTOSIZE );
52.

本文详细介绍了使用OpenCL和OpenCV进行图像旋转的host端程序代码,探讨了处理结果中出现暗点的原因,可能是由于浮点数到整数转换时的精度损失。当sin、cos值设为0.5时,图像没有暗纹,暗示可能的精度问题。作者计划在后续学习中继续研究这个问题。
2248

被折叠的 条评论
为什么被折叠?



