OpenCV中獲取圖像某一像素值
This is a basic example for the OpenCV.
First we must know the structure of IplImage:
IPL image:
IplImage
|-- int nChannels; // Number of color channels (1,2,3,4)
|-- int depth; // Pixel depth in bits:
| // IPL_DEPTH_8U,IPL_DEPTH_8S,
| // IPL_DEPTH_16U,IPL_DEPTH_16S,
| // IPL_DEPTH_32S,IPL_DEPTH_32F,
| // IPL_DEPTH_64F
|-- int width; // image width in pixels
|-- int height; // image height in pixels
|-- char* imageData; // pointer to aligned image data
| // Note that color images are stored in BGR order
|-- int dataOrder; // 0 - interleaved color channels,
| // 1 - separate color channels
| // cvCreateImage can only create interleaved images
|-- int origin; // 0 - top-left origin,
| // 1 - bottom-left origin (Windows bitmaps style)
|-- int widthStep; // size of aligned image row in bytes
|-- int imageSize; // image data size in bytes = height*widthStep
|-- struct _IplROI *roi;// image ROI.when not NULL specifies image
| // region to be processed.
|-- char *imageDataOrigin; // pointer to the unaligned origin of image data
| // (needed for correct image deallocation)
|
|-- int align; // Alignment of image rows:4 or 8 byte alignment
| // OpenCV ignores this and uses widthStep instead
|-- char colorModel[4]; // Color model - ignored by OpenCV
//------------------------------------------------------------------------------int main(int argc,char* argv[])
...{
IplImage *img=cvLoadImage("c://fruitfs.bmp",1);
CvScalar s;
for(int i=0;iheight;i++)...{
for(int j=0;jwidth;j++)...{
s=cvGet2D(img,i,j); // get the (i,j) pixel value
printf("B=%f,G=%f,R=%f ",s.val[0],s.val[1],s.val[2]);
s.val[0]=111;
s.val[1]=111;
s.val[2]=111;
cvSet2D(img,i,j,s);//set the (i,j) pixel value
}
}
cvNamedWindow("Image",1);
cvShowImage("Image",img);
cvWaitKey(0); //等待按鍵
cvDestroyWindow( "Image" );//銷毀窗口
cvReleaseImage( &img ); //釋放圖像
return 0;
}
其實還有更好的方法,例如將其封裝成類,調用起來更加方便,效率也很高.
opencv如何計算圖像中物體的像素值
opencv如何計算圖像中物體的像素值
其他人氣:924 ℃時間:2020-05-13 21:12:54
優(yōu)質解答
我來回答
類似推薦
- cosAcosB+sinAsinB=1 可得到什么
- 作文:游大夫山350字
- 計算:666×778+333×444=_.
- n個數(shù)的和的各個數(shù)位的和,等于這幾個數(shù)字各數(shù)位的和嗎
- We should _______ ______ _______them.我們應該友好的對待他們.
- 3fe2+ +2s2o3 2- +o2+xoH-1====fe3o4+S4O6 2- +2H2O 為什么說每生成1MOLfe3o4反應轉移的電子數(shù)為 4MOL
- 仰角的概念
- be blessed with 的意思及用法
- 3分之2比五分之四是否等于3比2=4比5
- 物體所受的合外力越大,
- 描寫顏色的詞語 如雪白的衣裳
- 6.28*(-23.3)-3.14*35.2-1.57*36.4 的簡便算法
猜你喜歡
- 1英語翻譯
- 2中國當前的主要矛盾,是人們日益增長的物質和文化生活和落后的社會生產(chǎn)之間的矛盾,具體表現(xiàn)在我們生活的哪些方面呢?
- 3如圖是一個平分角的儀器,其中AB=AD,BC=DC,將點A放在角的頂點,AB和AD沿著角的兩邊放正,沿AC畫一條射線AE,AE就是角平分線,請說明它的道理.
- 4what are you busy ( ) i'm busy ( )my homework
- 5我賭你等不起怎么翻譯
- 61×3/1+3×5/1+5×7/1+...+99×101/1 的值
- 7沙塵暴給人類的危害
- 8求有“蒼穹”二字的詩詞成語
- 9四十五分之十四除以(五分之一加三分之一)
- 1026414: finally, don't panic, think about what you can achieve, not what you can't. positive thinking is important !
- 11成語中的名人故事的由來?
- 12向醋酸溶液中加水稀釋,參考書上說氫離子濃度增加,這是怎么回事?