IplImage转为wxImage出现问题

下面是转换时用到的函数

#ifndef IPLTOWXIMAGE_H
#define IPLTOWXIMAGE_H

#include "cv.h"
#include "highgui.h"

void copy_and_swap_rb(char *s, char *d, int size)
{
	// Copy image data source s to destination d, swapping R and B channels.
	// Assumes 8 bit depth, 3 interleaved channels, and width_step = width*3
	const int step = 3;
	char *end = s + size;
	while (s<end) {
		d[0] = s[2];
		d[1] = s[1];
		d[2] = s[0];
		d += step;
		s += step;
	}
}

void wx2cv(wxImage &wx, IplImage *ipl)
{
	// Copy image data from wxWidgets image to Ipl (opencv) image
	// Assumes ipl image has seq "GBR", depth 8, and 3 channels, and
	// has the same size as the wxImage, and width_step = width*3.
	copy_and_swap_rb((char*)wx.GetData(), ipl->imageData, ipl->imageSize);
}

void cv2wx(IplImage *ipl, wxImage &wx )
{
	// Copy image data from Ipl (opencv) image to wxImage
	// Assumes ipl image has seq "GBR", depth 8, and 3 channels, and
	// has the same size as the wxImage, and width_step = width*3.
	copy_and_swap_rb( ipl->imageData, (char*)wx.GetData(),
		wx.GetWidth()*wx.GetHeight()*3);
}

IplImage *cv_from_wx(wxImage &wx)
{
	// Return a new IplImage copied from a wxImage.
	// Must be freed by user with cvReleaseImage().
	IplImage *ret = cvCreateImage(cvSize(wx.GetWidth(), wx.GetHeight()),
		IPL_DEPTH_8U, 3);
	wx2cv(wx, ret);
	return ret;
}

wxImage wx_from_cv( IplImage *cx)
{
	// Return new wxImage copied from a compatible IplImage.
	// Assumes ipl image has seq "BGR", depth 8, and 3 channels
	// Fear not. The copy on return is cheap; does not deep-copy the data.
	wxImage wx(cx->width, cx->height, (unsigned char*) malloc(cx->imageSize), false);//RGB
	cv2wx(cx, wx);
	return wx;
}
#endif

将IplImage转换为wxImage时,有时候会出现将彩色图像变为黑白的图像,图像出现问题
不知道是wx_from_cv这个方法的问题还是什么问题


采取了另外一种解决方法
将IplImage保存为一个实时图片文件,再去读取这个临时文件解决

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值