Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
color_resolver.cpp
Package: color.rar [view]
Upload User: ziyu85
Upload Date: 2022-04-24
Package Size: 1375k
Code Size: 6k
Category:
Special Effects
Development Platform:
Visual C++
- #include <iostream.h>
- #include <stdio.h>
- #include <string.h>
- #include<math.h>
- #include <stdlib.h>
- //#include <iomanip>
- char color_sort(int color_number) //颜色分类函数
- {
- char color_class[10][10];
- strcpy(color_class[0],"white"); //白色
- strcpy(color_class[1],"orange"); // 橙色
- strcpy(color_class[2],"brown"); // 褐色
- strcpy(color_class[3],"black"); // 黑色
- strcpy(color_class[4],"red"); // 红色
- strcpy(color_class[5],"yellow"); //黄色
- strcpy(color_class[6],"gray"); //灰色
- strcpy(color_class[7],"blue"); //蓝色
- strcpy(color_class[8],"green"); // 绿色
- strcpy(color_class[9],"purple"); // 紫色
- cout<<"The color of the picture is "<<color_class[color_number]<<endl;
- return(1);
- };
- double Euclid(double R,double G,double B)
- {
- double euclid;
- euclid=sqrt((R-G)*(R-G)+(R-B)*(R-B)+(G-B)*(G-B));//欧几里得距离
- return(euclid);
- }
- double color[3];
- double HsvToRgb(double H,double S,double V)
- {
- double var_h,var_i,var_r,var_g,var_b;
- double var_1,var_2,var_3;
- double f;
- if ( S == 0 ) //HSV values = 0 ÷ 1
- {
- color[0]= V * 255;
- color[1]= V * 255;
- color[2]= V * 255;
- }
- else
- {
- var_h = H / 6;
- //if ( var_h == 6 ) var_h = 0 ; //H must be < 1
- var_i = int( var_h ) ; //Or ... var_i = floor( var_h )
- f=var_h-var_i;
- var_1 = V * ( 1 - S );
- var_2 = V * ( 1 - S * f);
- var_3 = V * ( 1 - S * ( 1 - f ) );
- if ( var_i == 0 ) { var_r = V ; var_g = var_3 ; var_b = var_1 ;}
- else if ( var_i == 1 ) { var_r = var_2 ; var_g = V ; var_b = var_1 ;}
- else if ( var_i == 2 ) { var_r = var_1 ; var_g = V ; var_b = var_3 ;}
- else if ( var_i == 3 ) { var_r = var_1 ; var_g = var_2 ; var_b = V ;}
- else if ( var_i == 4 ) { var_r = var_3 ; var_g = var_1 ; var_b = V ;}
- else { var_r = V ; var_g = var_1 ; var_b = var_2 ;}
- color[0]= var_r * 255; //RGB results = 0 ÷ 255
- color[1]= var_g * 255;
- color[2]= var_b * 255;
- }
- cout<<"the picture'R= "<<color[0]<<endl<<"the picture'G= "<<color[1]<<endl<<"the picture'B= "<<color[2]<<endl;//setprecision(3)<<
- return(color[0],color[1],color[2]);
- }
- int main()
- {
- int color_number;
- int R;
- int G;
- int B;
- double H;
- double S;
- double V;
- double EUCLID;
- //输入HSV值
- cout<<"set the value of H"<<endl;
- cin>>H;
- cout<<"set the value of S"<<endl;
- cin>>S;
- cout<<"set the value of V"<<endl;
- cin>>V;
- //调用HsvToRgb函数
- HsvToRgb(H,S,V);
- R=(int)color[0];
- G=(int)color[1];
- B=(int)color[2];
- //限定RGB范围
- if(R<0||R>255)
- {cout<<"It is wrong of R"<<endl;
- }
- if(G<0||G>255)
- {cout<<"It is wrong of G"<<endl;
- }
- if(B<0||B>255)
- {cout<<"It is wrong of B"<<endl;
- }
- //颜色对应RGB规则
- if(0<=R&&R<=50)
- {if(0<=G&&G<=50)
- {if(0<=B&&B<=50)
- {
- EUCLID=Euclid(R,G,B);
- if(EUCLID<=30)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=3;
- color_sort(color_number);//黑色
- }}}}
- if(210<=R&&R<=255)
- {if(210<=G&&G<=255)
- {if(170<=B&&B<=255)
- {
- EUCLID=Euclid(R,G,B);
- if(EUCLID<=80)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=0;
- color_sort(color_number);//白色
- }}}}
- if(20<=R&&R<=210)
- {if(20<=G&&G<=210)
- {if(20<=B&&B<=210)
- {
- EUCLID=Euclid(R,G,B);
- if(EUCLID<=40)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=6;
- color_sort(color_number);//灰色
- }}}}
- if(130<=R&&R<=255)
- {if(0<=G&&G<=120)
- {if(0<=B&&B<=150)
- {
- EUCLID=Euclid(R,G,B);
- if(130<=EUCLID&&EUCLID<=365)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=4;
- color_sort(color_number);//红色
- }}}}
- if(0<=R&&R<=180)
- {if(0<=G&&G<=230)
- {if(100<=B&&B<=255)
- {
- EUCLID=Euclid(R,G,B);
- if(100<=EUCLID&&EUCLID<=365)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=7;
- color_sort(color_number);//蓝色
- }}}}
- if(0<=R&&R<=200)
- {if(100<=G&&G<=255)
- {if(0<=B&&B<=200)
- {
- EUCLID=Euclid(R,G,B);
- if(60<=EUCLID&&EUCLID<=365)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=8;
- color_sort(color_number);//绿色
- }}}}
- if(130<=R&&R<=255)
- {if(60<=G&&G<=170)
- {if(0<=B&&B<=10)
- {
- EUCLID=Euclid(R,G,B);
- if(160<=EUCLID&&EUCLID<=320)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=1;
- color_sort(color_number);//橙色
- }}}}
- if(70<=R&&R<=255)
- {if(30<=G&&G<=70)
- {if(30<=B&&B<=70)
- {
- EUCLID=Euclid(R,G,B);
- if(50<=EUCLID&&EUCLID<=280)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=2;
- color_sort(color_number);//褐色
- }}}}
- if(130<=R&&R<=255)
- {if(110<=G&&G<=255)
- {if(0<=B&&B<=10)
- {
- EUCLID=Euclid(R,G,B);
- if(180<=EUCLID&&EUCLID<=360)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=5;
- color_sort(color_number);//黄色
- }}}}
- if(90<=R&&R<=190)
- {if(0<=G&&G<=140)
- {if(130<=B&&B<=250)
- {
- EUCLID=Euclid(R,G,B);
- if(80<=EUCLID&&EUCLID<=270)
- {
- cout<<"The Euclidean distance of the picture is "<<EUCLID<<endl;//欧几里得距离
- color_number=9;
- color_sort(color_number);//紫色
- }}}}
- return(1);
- }