我有一个关于使用图像宽度和宽度步长的问题。
我有尺寸以及图像数据作为QByteArray。我还有widthstep。我的问题是如何使用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;
}
您必须考虑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);
}