【OpenCV】车牌定位RGB转HSV图像并打印输出各像素点的值

/*

蓝色BGR值范围:90

蓝色HSV值范围:110

*/

#include "stdafx.h"

#include
#include
#include
int main()
{
int R=0;
int G=0;
int B=0;
 IplImage *srcImage=cvLoadImage("24.bmp",1);
 IplImage* dstImage=cvCloneImage(srcImage);
 IplImage* HSVImage=0;
 HSVImage = cvCreateImage (cvGetSize (srcImage), 8, 3);
 cvCvtColor(srcImage, HSVImage, CV_BGR2HSV);
 //cvSaveImage("HSVImage",HSVImage);


CvScalar s;
  cvNamedWindow("srcImage", 1);
cvNamedWindow ("dstImage", 1);
cvNamedWindow ("HSVImage", 1);


 cvShowImage("srcImage",srcImage);
 //printf("weight=%d,height=%d,depth=%d,nchanel=%d",srcImage->width,srcImage->height,srcImage->depth,srcImage->nChannels);
 for(int y=0; yheight; y++)


{
for(int x=0; xwidth; x++)


{
s=cvGet2D(dstImage,y,x); //获取src图像中坐标为(i,j)的像素点的值
printf("x=%d,y=%d,BGR: B=%0.2f,G=%0.2f,R=%0.2f\n",x,y,s.val[0],s.val[1],s.val[2]);
s = cvGet2D(HSVImage, y, x);
printf("x=%d,y=%d,HSV: H=%0.2f,S=%0.2f,V=%0.2f\n",x,y,s.val[0],s.val[1],s.val[2]);

}
}
cvShowImage("dstImage",dstImage);
cvShowImage("HSVImage",HSVImage);
cvWaitKey(0);
cvReleaseImage (&srcImage);
cvReleaseImage (&dstImage);
cvReleaseImage (&HSVImage);
cvDestroyWindow("srcImage");
cvDestroyWindow("dstImage");
cvDestroyWindow("HSVImage");
return 0;

}


你可能感兴趣的:(OpenCV)