精品偷拍一区二区三区,亚洲精品永久 码,亚洲综合日韩精品欧美国产,亚洲国产日韩a在线亚洲

  • <center id="usuqs"></center>
  • 
    
  • opencv如何計算圖像中物體的像素值

    opencv如何計算圖像中物體的像素值
    其他人氣:924 ℃時間:2020-05-13 21:12:54
    優(yōu)質解答
    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;
    }
    其實還有更好的方法,例如將其封裝成類,調用起來更加方便,效率也很高.
    我來回答
    類似推薦
    請使用1024x768 IE6.0或更高版本瀏覽器瀏覽本站點,以保證最佳閱讀效果。本頁提供作業(yè)小助手,一起搜作業(yè)以及作業(yè)好幫手最新版!
    版權所有 CopyRight © 2012-2024 作業(yè)小助手 All Rights Reserved. 手機版