我需要将8位IplImage转换为32位IplImage.使用来自整个网络的文档,我尝试了以下方法:
// general code
img2 = cvCreateImage(cvSize(img->width, img->height), 32, 3);
int height = img->height;
int width = img->width;
int channels = img->nChannels;
int step1 = img->widthStep;
int step2 = img2->widthStep;
int depth1 = img->depth;
int depth2 = img2->depth;
uchar *data1 = (uchar *)img->imageData;
uchar *data2 = (uchar *)img2->imageData;
for(h=0;h<height;h++) for(w=0;w<width;w++) for(c=0;c<channels;c++) {
// attempt code...
}
// attempt one
// result: white image, two red spots which appear in the original image too.
// this is the closest result, what's …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个程序,它接受一个SDL_Surface
,将其转换为一个IplImage
,使用cvBlobsLib查找blob,将blob绘制为图像上的斑点,然后将输出转换IplImage
回SDL_Surface
.
我差点儿完成了:只将IplImage
背部转换为SDL_Surface
尚未完成.该IplImage具有3个图像通道,每像素8位.我想我可以使用两个电话:
SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
Run Code Online (Sandbox Code Playgroud)
我正在尝试SDL_CreateRGBsurfaceFrom
.但是,我不知道音高,Rmask,Gmask和Bmask的正确值是什么.(Amask为0,因为没有alpha通道.)
有人可以通过解释如何做到这一点来帮助我吗?
谢谢!
编辑:例如,这是我尝试使用的代码:
SDL_Surface *ipl_to_surface (IplImage *opencvimg)
{
int pitch = opencvimg->nChannels*opencvimg->width;
printf("Depth %d, nChannels %d, pitch %d\n", opencvimg->depth,
opencvimg->nChannels, pitch);
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom((void*)opencvimg->imageData,
opencvimg->width, …
Run Code Online (Sandbox Code Playgroud)