使用OpenCL+OpenCV实现图像旋转(二)

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

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.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值