04 cvScalar,CV_RGB 顏色

目的:

cvScalar 和  CV_RGB都是指定顏色

函數介紹:

cvScalar 顏色指定是 BGR

CV_RGB顏色指定是 RGB

參數值:

CvScalar s = cvScalar(double val0, double val1=0, double val2=0, double val3=0);

使用範例:

sample11_cvScalar_顏色BGR

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string.h>
#include <fstream>
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;

    // 畫出正方形的外框
    cvRectangle(image,
                cvPoint((width/4),(height/4)),
                cvPoint((width/4)*3,(height/4)*3),
                CV_RGB(255,0,0),3,CV_AA,1);

    cvRectangle(image,
                cvPoint((width/4)*4,(height/4)),
                cvPoint((width/4)*6,(height/4)*3),
                cvScalar(255,0,0),3,CV_AA,1);

    cvShowImage("image",image);
    waitKey(0);

    cvDestroyAllWindows();
    cvReleaseImage(&image);
    system("pause");
    return 0;
}

結果:

Screen Shot 2015-03-01 at 10.41.47 AM

補充資料:

Black = cCvScalar::new_object(cvScalar(0x0,0x0,0x0))
Silver = cCvScalar::new_object(cvScalar(0x0c,0x0c,0x0c))
Gray = cCvScalar::new_object(cvScalar(0x80,0x80,0x80))
White = cCvScalar::new_object(cvScalar(0xff,0xff,0xff))
Maroon = cCvScalar::new_object(cvScalar(0x0,0x0,0x80))
Red = cCvScalar::new_object(cvScalar(0x0,0x0,0xff))
Purple = cCvScalar::new_object(cvScalar(0x80,0x0,0x80))
Fuchsia = cCvScalar::new_object(cvScalar(0xff,0x0,0xff))
Green = cCvScalar::new_object(cvScalar(0x0,0x80,0x0))
Lime = cCvScalar::new_object(cvScalar(0x0,0xff,0x0))
Olive = cCvScalar::new_object(cvScalar(0x0,0x80,0x80))
Yellow = cCvScalar::new_object(cvScalar(0x0,0xff,0xff))
Navy = cCvScalar::new_object(cvScalar(0x80,0x0,0x0))
Blue = cCvScalar::new_object(cvScalar(0xff,0x0,0x0))
Teal = cCvScalar::new_object(cvScalar(0x80,0x80,0x0))
Aqua = cCvScalar::new_object(cvScalar(0xff,0xff,0x0))