1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| #include "opencv2/highgui/highgui.hpp" #include <iostream>
using namespace cv; using namespace std;
int main() { IplImage* img = cvLoadImage("test.png", 1);
IplImage* hsv = cvCreateImage(cvGetSize(img), 8, 3); cvCvtColor(img, hsv, CV_BGR2HSV);
IplImage* Bimg = cvCreateImage(cvGetSize(img), 8, 1); IplImage* Gimg = cvCreateImage(cvGetSize(img), 8, 1); IplImage* Rimg = cvCreateImage(cvGetSize(img), 8, 1); cvSplit(img, Bimg, Gimg, Rimg, 0);
IplImage* pImg1 = cvCreateImage(cvGetSize(img), 8, 3); IplImage* pImg2 = cvCreateImage(cvGetSize(img), 8, 3); IplImage* pImg3 = cvCreateImage(cvGetSize(img), 8, 3); cvSetZero(pImg1); cvSetZero(pImg2); cvSetZero(pImg3); cvMerge(Bimg, 0, 0, 0, pImg3); cvMerge(0, Gimg, 0, 0, pImg2); cvMerge(0, 0, Rimg, 0, pImg1);
IplImage* Himg = cvCreateImage(cvGetSize(hsv), 8, 1); IplImage* Simg = cvCreateImage(cvGetSize(hsv), 8, 1); IplImage* Vimg = cvCreateImage(cvGetSize(hsv), 8, 1); IplImage* HSV1 = cvCreateImage(cvGetSize(hsv), 8, 3); IplImage* HSV2 = cvCreateImage(cvGetSize(hsv), 8, 3); IplImage* HSV3 = cvCreateImage(cvGetSize(hsv), 8, 3); cvSplit(hsv, Vimg, Simg, Himg, 0);
cvSetZero(HSV1); cvSetZero(HSV2); cvSetZero(HSV3); cvMerge(Vimg, 0, 0, 0, HSV3); cvMerge(0, Simg, 0, 0, HSV2); cvMerge(0, 0, Himg, 0, HSV1);
cvNamedWindow("HSV", WINDOW_AUTOSIZE); cvShowImage("HSV", hsv);
namedWindow("H", WINDOW_AUTOSIZE); cvShowImage("H", HSV1); namedWindow("S", WINDOW_AUTOSIZE); cvShowImage("S", HSV2); namedWindow("V", WINDOW_AUTOSIZE); cvShowImage("V", HSV3);
cvNamedWindow("RGB", WINDOW_AUTOSIZE); cvShowImage("RGB", img);
namedWindow("R", WINDOW_AUTOSIZE); cvShowImage("R", pImg1); namedWindow("G", WINDOW_AUTOSIZE); cvShowImage("G", pImg2); namedWindow("B", WINDOW_AUTOSIZE); cvShowImage("B", pImg3);
cvWaitKey(0);
return 0; }
|