Alex_grem 0 Жалоба Опубликовано November 9, 2009 Скажите, пожалуйста, что обозначает параметр widthStep в структуре IplImage? Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Dasdranagon 1 Жалоба Опубликовано November 9, 2009 Скажите, пожалуйста, что обозначает параметр widthStep в структуре IplImage? The parameter widthStep contains the number of bytes between points in the same column and successive rows (similar to the ”step” parameter of CvMat (the length of a row in bytes, not ints or floats)). См.: "Learning OpenCV" Gary Bradski and Adrian Kaehler Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Alex_grem 0 Жалоба Опубликовано November 9, 2009 The parameter widthStep contains the number of bytes between points in the same column and successive rows (similar to the ”step” parameter of CvMat (the length of a row in bytes, not ints or floats)). См.: "Learning OpenCV" Gary Bradski and Adrian Kaehler А русским языком слабо объяснить, ну не англичанин я! Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Dasdranagon 1 Жалоба Опубликовано November 9, 2009 А русским языком слабо объяснить, ну не англичанин я! Sorry, i havn't russian keyboard now. Try to understand follows: The other trick to know is that the step element in the matrix array is the length in bytes of a row in the matrix. In that structure, cols or width alone is not enough to move between matrix rows because, for machine efficiency, matrix or image allocation is done to the nearest four-byte boundary. Thus a matrix of width three bytes would be allocated four bytes with the last one ignored. For this reason, if we get a byte pointer to a data element then we add step to the pointer in order to step it to the next row directly below our point. If we have a matrix of integers or floating-point numbers and corresponding int or float pointers to a data element, we would step to the next row by adding step/4; for doubles, we’d add step/8 (this is just to take into account that C will automatically multiply the offsets we add by the data type’s byte size). Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Smorodov 579 Жалоба Опубликовано November 9, 2009 Sorry, i havn't russian keyboard now. Try to understand follows: The other trick to know is that the step element in the matrix array is the length in bytes of a row in the matrix. In that structure, cols or width alone is not enough to move between matrix rows because, for machine efficiency, matrix or image allocation is done to the nearest four-byte boundary. Thus a matrix of width three bytes would be allocated four bytes with the last one ignored. For this reason, if we get a byte pointer to a data element then we add step to the pointer in order to step it to the next row directly below our point. If we have a matrix of integers or floating-point numbers and corresponding int or float pointers to a data element, we would step to the next row by adding step/4; for doubles, we’d add step/8 (this is just to take into account that C will automatically multiply the offsets we add by the data type’s byte size). widthStep - Параметр, определяющий расстояние между соседними по вертикали точками изображения. Нужен т.к. количество байтов по ширине картинке может быть не равно количеству точек по горизонтали (как пример можно привести бинарное изображение 1 байт - 8 точек, а если ширина изображения не кратна 8, то тут и нужен параметр widthStep). Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Alex_grem 0 Жалоба Опубликовано November 9, 2009 widthStep - Параметр, определяющий расстояние между соседними по вертикали точками изображения. Нужен т.к. количество байтов по ширине картинке может быть не равно количеству точек по горизонтали (как пример можно привести бинарное изображение 1 байт - 8 точек, а если ширина изображения не кратна 8, то тут и нужен параметр widthStep). Если честно, не понимаю про что идет речь. Какие точки в 1 байте? есть ли какие-нибудь ссылки на данную тему? Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Smorodov 579 Жалоба Опубликовано November 9, 2009 Если честно, не понимаю про что идет речь. Какие точки в 1 байте? есть ли какие-нибудь ссылки на данную тему? Разве что здесь посмотреть: http://www.compvision.ru/forum/index.php?showtopic=121 и здесь: http://www.compvision.ru/forum/index.php?showtopic=78 Остальное экспериментом. Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах
Dasdranagon 1 Жалоба Опубликовано November 9, 2009 I found a nice example to understand what means "widthStep". In case of 3-channel image img->widthStep= ( img->width + 1) * 4 //////////////////////////////////////////////////////////////////////// // // hello-world.cpp // // This is a simple, introductory OpenCV program. The program reads an // image from a file, inverts it, and displays the result. // //////////////////////////////////////////////////////////////////////// #include <stdlib.h> #include <stdio.h> #include <math.h> #include <cv.h> #include <highgui.h> int main(int argc, char *argv[]) { IplImage* img = 0; int height,width,step,channels; uchar *data; int i,j,k; if(argc<2){ printf("Usage: main <image-file-name>\n\7"); exit(0); } img=cvLoadImage(argv[1]); // load an image if(!img){ printf("Could not load image file: %s\n",argv[1]); exit(0); } // get the image data height = img->height; width = img->width; step = img->widthStep; channels = img->nChannels; data = (uchar *)img->imageData; printf("Processing a %dx%d image with %d channels, step= %d\n",height,width,channels,step); // create a window cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); cvMoveWindow("mainWin", 100, 100); // invert the image for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++) data[i*step+j*channels+k]=255-data[i*step+j*channels+k]; // show the image cvShowImage("mainWin", img ); // wait for a key cvWaitKey(0); // release the image cvReleaseImage(&img ); return 0; } [/codebox] Source: http://www.cs.iit.edu/~agam/cs512/lect-not...encv-intro.html Поделиться сообщением Ссылка на сообщение Поделиться на других сайтах