01 cvInRangeS 找出皮膚的顏色

目的:

cvInRangeS 找出特定的顏色

函數介紹:

cvInRangeS 找出特定的顏色,找到的話,就顯示為白色,不然為黑色。

參數值:

C: void cvInRangeS(const CvArr* src, CvScalar lower, CvScalar upper, CvArr* dst)
Parameters:
  • src – first input array.
  • lowerb – inclusive lower boundary array or a scalar.
  • upperb – inclusive upper boundary array or a scalar.
  • dst – output array of the same size as src and CV_8U type.

使用範例:

sample12-1_cvInRangeS_找出皮膚顏色
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include
#include
#include
using namespace cv;
int main(int argc,char **argv)
{
    int width,height;
    if(argc<=1)
    {
        std::cout<<"Error:Please Load a picture!"<<std::endl;         return 0;     }     IplImage *image;     //建立視窗     namedWindow("image",CV_WINDOW_AUTOSIZE);     //讀取圖片     image=cvLoadImage(argv[1]);     width=image->width;
    height=image->height;

    // 畫出正方形的外框

    IplImage * img2=cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);

      cvInRangeS(image, cvScalar(90,110,180), cvScalar(139,164,236), img2);

    cvShowImage("image", image);

    waitKey(0);
    cvShowImage("image2", img2);

    waitKey(0);

    cvDestroyAllWindows();
    return 0;
}

結果:

Screen Shot 2015-03-01 at 1.44.47 PM

補充資料:

OpenCV
CH01 簡介CH02 OpenCV APICH03 繪圖CH04 應用範例CH06 haarcascadesCH06 surf和siftCH07 OCRCH09 FaceCH5 輪廓(findContours、drawContours)