我搜索了将IplImage*转换为Mat,但所有答案都是关于转换为cvMat的.
我该怎么做?Mat和cvMat有什么区别?
提前致谢
我刚刚开始学习OpenCV"使用OpenCV库学习OpenCV计算机视觉".
在演示如何显示图片的第一个示例中,它有一条线
IplImage* img = cvLoadImage("name.type")
Run Code Online (Sandbox Code Playgroud)
虽然这本书解释了它,但我仍然不完全知道究竟是IplImage* img做什么的.
cvLoadImage是否将图像加载到IplImage指向的img?有人能解释一下吗?谢谢
什么IplImage在OpenCV?你能解释一下它的含义吗?我们什么时候应该使用它?
谢谢.
我需要将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) 我试图在OpenCV中旋转图像.
我使用了Stack Overflow上的代码:
Mat source(img);
Point2f src_center(source.cols/2.0, source.rows/2.0);
Mat rot_mat = getRotationMatrix2D(src_center, 40.0, 1.0);
Mat dst;
warpAffine(source, dst, rot_mat, source.size());
Run Code Online (Sandbox Code Playgroud)
一旦我dst Mat填充了变量类型,我想把它放回IplImage变量类型,任何想法如何做到这一点?
我遇到了openCv IplImage裁剪的问题.假设tmp和img都是IplImage*.使用代码:
printf("Orig dimensions: %dx%d\n", img->width, img->height);
cvSetImageROI(img, cvRect(0, 0,500,500));
tmp = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvCopy(img, tmp, NULL);
cvResetImageROI(img);
img = cvCloneImage(tmp);
printf("Orig dimensions after crop: %dx%d\n", tmp->width, tmp->height);
Run Code Online (Sandbox Code Playgroud)
当我使用上面的cvRect时,我会得到一个像预期的那样裁剪尺寸为500 x500的图像,但是当我使用rect(400,400,500,500)时,我会得到尺寸为500 X 320的图像.
我正在尝试编写一个程序,它接受一个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) 我正在尝试访问IplImage的Pixel by Pixel.我使用Java和Processing,有时我需要逐像素访问.到目前为止我已经这样做了,但我不知道出了什么问题:
public IplImage PImageToIplImage(PImage imageSrc)
{
IplImage imageDst;
if(imageSrc.format==RGB)
{
imageDst = IplImage.create(imageSrc.width, imageSrc.height, IPL_DEPTH_8U, 3);
ByteBuffer imagePixels=imageDst.getByteBuffer();
int locPImage, locIplImage, x, y;
for(y=0; y<imageSrc.height; y++)
for(x=0; x<imageSrc.width; x++)
{
locPImage = x + y * width;
locIplImage=y*imageDst.widthStep()+3*x;
imagePixels.put(locIplImage+2, (byte)(red(imageSrc.pixels[locPImage])));
imagePixels.put(locIplImage+1, (byte)(green(imageSrc.pixels[locPImage])));
imagePixels.put(locIplImage, (byte)(blue(imageSrc.pixels[locPImage])));
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Karlphilip消化之后,我来到这里,仍然没有工作.当我尝试显示时,它给了我一个nullPointer异常:
imageDst = IplImage.create(imageSrc.width, imageSrc.height, IPL_DEPTH_8U, 3);
CvMat imagePixels = CvMat.createHeader(imageDst.height(), imageDst.width(), CV_32FC1);
cvGetMat(imageDst, imagePixels, null, 0);
int locPImage, x, y;
for(y=0; y<imageSrc.height; y++)
for(x=0; x<imageSrc.width; x++)
{
locPImage = x …Run Code Online (Sandbox Code Playgroud) 我很熟悉OpenCV 1.1中使用的IPL图像格式.但是我使用的是最新的2.4版本,并希望切换到OpenCV的C++界面.这是我访问图像中像素的方法:
int step = img->widthStep;
int height = img->height;
int width = img->width;
unsigned char* data = (unsigned char*) img->imageData;
for (int i=0; i<height; i++)
{
for (int j=0; j<step; j+=3) // 3 is the number of channels.
{
if (data[i*step + j] > 200) // For blue
data[i*step + j] = 255;
if (data[i*step + j + 1] > 200) // For green
data[i*step + j + 1] = 255;
if (data[i*step + j + 2] > 200) …Run Code Online (Sandbox Code Playgroud) 我现在正在使用JavaCV,尝试一些简单的blob检测.我正在使用maven并从他们的存储库获得JavaCV 0.11(更具体的org.bytedeco.javacv).一切都编译没有错误,工作正常,但从BufferedImage创建IplImage的方法似乎不存在.Eclipse说
The method createFrom(BufferedImage) is undefined for the type opencv_core.IplImage
Run Code Online (Sandbox Code Playgroud)
我不知道问题是什么,因为除了这个方法到目前为止一切正常.