【发布时间】:2013-11-01 15:25:12
【问题描述】:
我正在使用 Cimg 库进行图像处理工作。我有一个由 GPU 返回的数组的指针,我想让 Cimg 对象直接取数组的值。现在,我正在使用 for 循环来完成这项工作,但效率不高。
我现在使用的示例代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "CImg.h"
using namespace std;
using namespace cimg_library;
int main(){
char pause;
int width=3; int height=3;//Dimension of the Cimg matrix
int size = width * height * sizeof(int); // number of bytes in total in arrays
int *ptr = (int*) malloc(size);
//Assign the array some example value;
for (int m=0;m<width*height;m++){
*(ptr+m)=m;
}
CImg<int> img(width,height,1,1);
//This is how I assign the value of the array to the Cimg object
for (int i=0;i<width;i++)
for (int j=0;j<height;j++)
{
img.atXY(i,j)=*(ptr+j*width+i);
}
img.save_bmp("img.bmp");
cout<<"Pause:";
cin>>pause;
}
}
我厌倦了这段代码,但它不起作用:
img.begin()=ptr;
谁能帮我消除for循环并提高速度?提前谢谢大家。
【问题讨论】: