【问题标题】:Image width and widthstep, now what?图像宽度和宽度步长,现在呢?
【发布时间】:2013-02-03 16:51:30
【问题描述】:

我有一个关于使用图像宽度和宽度步长的问题。

我将尺寸和图像数据作为 QByteArray。我也有宽度步。我的问题是如何使用 widthstep 正确填充 Ipl 图像,因为我的图像宽度是 4095,它不是 8 的整数倍。我已经成功填充了宽度为 8 整数倍的图像,但现在我被困住了手头的问题。任何使用 widthstep 填充 IplImage 的通用代码都将受到欢迎和高度赞赏。 :D

这是我的开关盒中有效的部分;默认图片宽度为 8 的整数倍:

default:
      {
          IplImage* extracted_sar_image; // our image declaration
          CvSize size; // size type has width and height attributes
          size.height = sar_nrows_integer; // height of size
          size.width = sar_ncols_integer;

          extracted_sar_image = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
          extracted_sar_image->imageData = sar_image_data_2.data();         

          cvNamedWindow("Image", CV_WINDOW_NORMAL );
          cvShowImage("Image", extracted_sar_image); 
          cvMoveWindow("Image", 100, 100);
          cvSaveImage("C:/Users/z_slant/Desktop/generated_extracted_sar_image.bmp", extracted_sar_image); 
          // delay to observe the image that is being saved
          cvWaitKey(10000); 
          // deallocates the image data
          cvReleaseImage(&extracted_sar_image); 
          // closes image display window
          cvDestroyWindow("Image"); 

      break;
      }

【问题讨论】:

    标签: qt opencv iplimage qbytearray


    【解决方案1】:

    您必须考虑 openCV 结构中的字节对齐。

    openCV IplImage 中的 1 行是 widthStep 字节长

    QbyteArray 中的 1 行是宽字节长

    因此,逐行复制数据应该没问题。

    qByteArray myArray;
    IplImage* extracted_sar_image; // our image declaration
    CvSize size; // size type has width and height attributes
    size.height = sar_nrows_integer; // height of size
    size.width = sar_ncols_integer;
    
    extracted_sar_image = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
    
    for (int row = 0 ; row < size.height ;row++)
    {
        memcpy(&extracted_sar_image->imageData[row*extracted_sar_image->widthStep],&myArray.data()[row*size.width],size.width);
    }
    

    【讨论】:

    • 谢谢特洛普。我会试试这个,让你知道我是否能够让它工作。 :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    • 2010-11-18
    • 1970-01-01
    相关资源
    最近更新 更多