最有效地种植的IplImage [英] cropping IplImage most effectively

查看:131
本文介绍了最有效地种植的IplImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道什么是OpenCV的剪裁IplImage结构的最有效途径。我现在做到以下几点,但似乎过于复杂,我敢肯定有做事情的一个更好的方式。

I wonder what is the most effective way of cropping an IplImage in opencv. I currently do the following, but it seems too complicated and I'm sure there's a better way of doing things.

    // set ROI on original image, create 'tmp' image and copy data over.
    cvSetImageROI(orig_image, cvRect(55, 170, 530, 230));

    IplImage *tmp = cvCreateImage(cvGetSize(orig_image),
                               orig_image->depth,
                               orig_image->nChannels);

    cvCopy(m_depth_run_avg, tmp, NULL);
    cvResetImageROI(orig_image);

    // copy temporary image back to original image.
    IplImage *orig_image= cvCreateImage(cvGetSize(tmp),
                           tmp->depth,
                           tmp->nChannels);
    cvCopy(tmp, orig_image, NULL);

有没有更好的方式来裁剪图像?

is there a better way to crop a image?

推荐答案

,有。你似乎在最后要重新创建原始图像。这是没有必要的,如下面的code所示:

Yes, there is. You seem to be recreating the original image at the end. That is not necessary, as the following code demonstrates:

IplImage* orig = cvLoadImage("test.jpg");
if (!orig)
{
    return -1;
}
printf("Orig dimensions: %dx%d\n", orig->width, orig->height);

cvSetImageROI(orig, cvRect(0, 250, 350, 350));

IplImage *tmp = cvCreateImage(cvGetSize(orig),
                               orig->depth,
                               orig->nChannels);

cvCopy(orig, tmp, NULL);
cvResetImageROI(orig);

orig = cvCloneImage(tmp);
printf("Orig dimensions after crop: %dx%d\n", orig->width, orig->height);

cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
cvShowImage( "result", orig);
cvWaitKey( 0 );
cvDestroyWindow( "result" );

不幸的是,你创建一个临时图像存储的结果cvCopy的当务之急()

这篇关于最有效地种植的IplImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆