void Board::fillGouraudTriangle( const Point & p1, const float brightness1, const Point & p2, const float brightness2, const Point & p3, const float brightness3, unsigned char divisions, int depth /* = -1 */ ) { Color color1( _state.penColor ); Color color2( _state.penColor ); Color color3( _state.penColor ); color1.red( static_cast<unsigned char>( std::min( 255.0f, color1.red() * brightness1 ) ) ); color1.green( static_cast<unsigned char>( std::min( 255.0f, color1.green() * brightness1 ) ) ); color1.blue( static_cast<unsigned char>( std::min( 255.0f, color1.blue() * brightness1 ) ) ); color2.red( static_cast<unsigned char>( std::min( 255.0f, color2.red() * brightness2 ) ) ); color2.green( static_cast<unsigned char>( std::min( 255.0f, color2.green() * brightness2 ) ) ); color2.blue( static_cast<unsigned char>( std::min( 255.0f, color2.blue() * brightness2 ) ) ); color3.red( static_cast<unsigned char>( std::min( 255.0f, color3.red() * brightness3 ) ) ); color3.green( static_cast<unsigned char>( std::min( 255.0f, color3.green() * brightness3 ) ) ); color3.blue( static_cast<unsigned char>( std::min( 255.0f, color3.blue() * brightness3 ) ) ); fillGouraudTriangle( Point( _state.unit(p1.x), _state.unit(p1.y) ), color1, Point( _state.unit(p2.x), _state.unit(p2.y) ), color2, Point( _state.unit(p3.x), _state.unit(p3.y) ), color3, divisions, depth ); }
void TriMeshModel::addTriangleWithFace(Eigen::Vector3f& vertex1, Eigen::Vector3f& vertex2, Eigen::Vector3f& vertex3, Eigen::Vector4f& vertexColor1, Eigen::Vector4f& vertexColor2, Eigen::Vector4f& vertexColor3) { Eigen::Vector3f normal = TriMeshModel::CreateNormal(vertex1, vertex2, vertex3); VisualizationFactory::Color color1(vertexColor1(0), vertexColor1(1), vertexColor1(2), vertexColor1(4)); VisualizationFactory::Color color2(vertexColor2(0), vertexColor2(1), vertexColor2(2), vertexColor2(4)); VisualizationFactory::Color color3(vertexColor3(0), vertexColor3(1), vertexColor3(2), vertexColor3(4)); addTriangleWithFace(vertex1, vertex2, vertex3, normal, color1, color2, color3); }
void v4coloru_object::test<17>() { F32 r = 23.f, g = 12.32f, b = -12.3f; LLColor3 color3(r,g,b); LLColor4U llcolor4u; llcolor4u.setVecScaleClamp(color3); const S32 MAX_COLOR = 255; F32 color_scale_factor = MAX_COLOR/r; S32 r2 = llround(r * color_scale_factor); S32 g2 = llround(g * color_scale_factor); ensure("setVecScaleClamp():Fail to add the value ", ((r2 == llcolor4u.mV[VX]) && (g2 == llcolor4u.mV[VY]) && (0 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW]))); }
void Jogo::encerramento() { gui.musicaFundo.stop(); gui.success.play(); sf::Color color1(255,255,255,255); sf::Color color2(100,100,100,255); sf::Color color3(255,0,0,255); while(gui.tela.isOpen()) { gui.limpaTela(); gui.desenhaFundo(this->level); gui.desenhaTexto("Você venceu!", 60, color1, gui.getWidth()/2, gui.getHeigth()/1.8, true); gui.desenhaTexto("Tempo: " + to_string(antesVirgula) + "." + to_string(depoisVirgula), 40, color3, gui.getWidth()/2, gui.getHeigth()/1.23, true); gui.desenhaTexto("ESPAÇO - Jogar novamente", 25, color2, gui.getWidth()/20, gui.getHeigth()/1.3, false); gui.desenhaTexto("ESC - Encerrar o jogo", 25, color2, gui.getWidth()/20, gui.getHeigth()/1.2, false); sf::Event evento; while (gui.tela.pollEvent(evento)) { switch(evento.type) { case(sf::Event::Closed): gui.tela.close(); break; case(sf::Event::KeyPressed): { if(evento.key.code == sf::Keyboard::Escape) { gui.tela.close(); } else if(evento.key.code == sf::Keyboard::Space) { this->level = 0; for(int i = 0; i < 5; i++) this->lixeiras[i].zera(); run(); } break; } default: break; } } gui.renderiza(); } }
// 绘制羽化文字 void DrawEclosionText(HDC hDC, LPCTSTR lpszText, LPCTSTR lpszFontName, int nFontSize) { int nWidth = 56, nHeight = 16; Gdiplus::Bitmap bmp(nWidth, nHeight, 0, PixelFormat32bppARGB, NULL); Gdiplus::Graphics graphics(&bmp); Gdiplus::GraphicsPath path(Gdiplus::FillModeAlternate); Gdiplus::FontFamily fontFamily(lpszFontName, NULL); Gdiplus::StringFormat strFmt(0, 0); Gdiplus::RectF rc(0.0f, 0.0f, nWidth, nHeight); path.AddString(lpszText, -1, &fontFamily, Gdiplus::FontStyleBold, nFontSize, rc, &strFmt); Gdiplus::Matrix matrix(1.0f/* / 5.0f*/, 0.0f, 0.0f, 1.0f/* / 5.0f*/, -1.0f/* / 5.0f*/, -1.0f/* / 5.0f*/); graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); graphics.SetTransform(&matrix); Gdiplus::Color color((Gdiplus::ARGB)0x55CCE0EE); Gdiplus::Pen pen(color, 3); graphics.DrawPath(&pen, &path); Gdiplus::Color color2((Gdiplus::ARGB)0x55CCE0EE); Gdiplus::SolidBrush brush(color2); graphics.FillPath(&brush, &path); Gdiplus::Bitmap bmp2(300, 40, 0, PixelFormat32bppARGB, NULL); Gdiplus::Graphics graphics2(&bmp2); graphics2.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); graphics2.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic); graphics2.DrawImage(&bmp, 0, 0, nWidth, nHeight); Gdiplus::Color color3((Gdiplus::ARGB)0xFF000000); Gdiplus::SolidBrush brush2(color3); graphics2.FillPath(&brush2, &path); CLSID clsid; ::CLSIDFromString(_T("{557CF406-1A04-11D3-9A73-0000F81EF32E}"), &clsid); bmp2.Save(_T("c:\\CoolText.png"), &clsid, NULL); Gdiplus::Graphics graphics3(hDC); graphics3.DrawImage(&bmp2, 8, 4); }
void ColorTest::configuration() { Corrade::Utility::Configuration c; Color3f color3(0.5f, 0.75f, 1.0f); std::string value3("0.5 0.75 1"); c.setValue("color3", color3); CORRADE_COMPARE(c.value("color3"), value3); CORRADE_COMPARE(c.value<Color3f>("color3"), color3); Color4f color4(0.5f, 0.75f, 0.0f, 1.0f); std::string value4("0.5 0.75 0 1"); c.setValue("color4", color4); CORRADE_COMPARE(c.value("color4"), value4); CORRADE_COMPARE(c.value<Color4f>("color4"), color4); }
QVector<QPair<QColor, int> > *MainWindow::makeColors() { QVector<QPair<QColor, int> > *colors = new QVector<QPair<QColor, int > >(); QColor color1(128,0,0); QColor color2(255,0,0); QColor color3(0,128,0); QColor color4(0,255,0); QColor color5(0,0,128); QColor color6(0,0,255); colors->push_back(QPair<QColor, int>(color1, 2)); colors->push_back(QPair<QColor, int>(color2, 2)); colors->push_back(QPair<QColor, int>(color3, 2)); colors->push_back(QPair<QColor, int>(color4, 2)); colors->push_back(QPair<QColor, int>(color5, 2)); colors->push_back(QPair<QColor, int>(color6, 2)); return colors; }
// Blinn Phong specular color3 Ray::specularColor(Light light, Material material, Fragment fragment) const { vec3 lightDir = normalize( light.position - fragment.position); vec3 viewDir = -direction; //vec3 r = 2 * (dot(lightDir, fragment.normal))*fragment.normal - lightDir; vec3 halfVector = normalize(lightDir + viewDir); color3 specular; // if self shadow, specular = 0.0 if (dot(lightDir, fragment.normal) < 0.0) { specular = color3(0.0); } else { // specular = Is * ks * cosPhi^alpha float specularShine = pow(max(dot(fragment.normal, halfVector), 0.0f), material.shininess); // Blinn Phong specular //specularShine = pow(max(dot(r, viewDir), 0.0), material.shininess); // original Phong specular specular = light.specular * material.ks * specularShine; } return specular; }
void MainWindow::createActions() { openAct = new QAction("&Open", this); connect(openAct, SIGNAL(triggered()), this, SLOT(openAndReadFile())); exitAct = new QAction("E&xit", this); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); aboutAct = new QAction("&About", this); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); statAct = new QAction("&Stat", this); connect(statAct, SIGNAL(triggered()), this, SLOT(showStat())); resetAct = new QAction("&Reset position", this); resetAct->setStatusTip("Reset the position"); connect(resetAct, SIGNAL(triggered()), this, SLOT(reset())); reseteffectAct = new QAction("&Reset", this); reseteffectAct->setStatusTip("Reset all material"); connect(reseteffectAct, SIGNAL(triggered()), this, SLOT(reseteffect())); //ANIMATION----------------------------------------------------- animationShownAct = new QAction("&Shown", this); animationShownAct->setStatusTip("Show animation"); animationShownAct->setCheckable(true); connect(animationShownAct, SIGNAL(triggered()), this, SLOT(showAnimation())); animationHiddenAct = new QAction("&Hidden", this); animationHiddenAct->setStatusTip("Hide animation"); animationHiddenAct->setCheckable(true); connect(animationHiddenAct, SIGNAL(triggered()), this, SLOT(hideAnimation())); animationGroup = new QActionGroup(this); animationGroup->addAction(animationShownAct); animationGroup->addAction(animationHiddenAct); animationHiddenAct->setChecked(true); //COLOR----------------------------------------------------- color0Act = new QAction("&No light",this); color0Act->setStatusTip("No light"); color0Act->setCheckable(true); connect(color0Act, SIGNAL(triggered()), this, SLOT(color0())); color1Act = new QAction("&Red",this); color1Act->setStatusTip("Red"); color1Act->setCheckable(true); connect(color1Act, SIGNAL(triggered()), this, SLOT(color1())); color2Act = new QAction("&Green",this); color2Act->setStatusTip("Green"); color2Act->setCheckable(true); connect(color2Act, SIGNAL(triggered()), this, SLOT(color2())); color3Act = new QAction("&Blue",this); color3Act->setStatusTip("Blue"); color3Act->setCheckable(true); connect(color3Act, SIGNAL(triggered()), this, SLOT(color3())); color10Act = new QAction("&White",this); color10Act->setStatusTip("White"); color10Act->setCheckable(true); connect(color10Act, SIGNAL(triggered()), this, SLOT(color10())); colorGroup = new QActionGroup(this); colorGroup->addAction(color0Act); colorGroup->addAction(color1Act); colorGroup->addAction(color2Act); colorGroup->addAction(color3Act); colorGroup->addAction(color10Act); color10Act->setChecked(true); //EFFECT----------------------------------------------------- effect0Act = new QAction("&No effect",this); effect0Act->setStatusTip("No effect"); effect0Act->setCheckable(true); connect(effect0Act, SIGNAL(triggered()), this, SLOT(effect0())); effect1Act = new QAction("&Ambient",this); effect1Act->setStatusTip("Ambient"); effect1Act->setCheckable(true); connect(effect1Act, SIGNAL(triggered()), this, SLOT(effect1())); effect2Act = new QAction("&Diffuse",this); effect2Act->setStatusTip("Diffuse"); effect2Act->setCheckable(true); connect(effect2Act, SIGNAL(triggered()), this, SLOT(effect2())); effect10Act = new QAction("&All",this); effect10Act->setStatusTip("All effect"); effect10Act->setCheckable(true); connect(effect10Act, SIGNAL(triggered()), this, SLOT(effect10())); effectGroup = new QActionGroup(this); effectGroup->addAction(effect0Act); effectGroup->addAction(effect1Act); effectGroup->addAction(effect2Act); effectGroup->addAction(effect10Act); effect10Act->setChecked(true); //AMBIENT----------------------------------------------------- ambient0Act = new QAction("&No Ambient",this); ambient0Act->setStatusTip("No Ambient"); ambient0Act->setCheckable(true); connect(ambient0Act, SIGNAL(triggered()), this, SLOT(ambient0())); ambient1Act = new QAction("&Ambient",this); ambient1Act->setStatusTip("Ambient"); ambient1Act->setCheckable(true); connect(ambient1Act, SIGNAL(triggered()), this, SLOT(ambient1())); ambient2Act = new QAction("&Ambient Color",this); ambient2Act->setStatusTip("Ambient Color"); ambient2Act->setCheckable(true); connect(ambient2Act, SIGNAL(triggered()), this, SLOT(ambient2())); ambientGroup = new QActionGroup(this); ambientGroup->addAction(ambient0Act); ambientGroup->addAction(ambient1Act); ambientGroup->addAction(ambient2Act); ambient0Act->setChecked(true); //DIFFUSE----------------------------------------------------- diffuse0Act = new QAction("&No Diffuse",this); diffuse0Act->setStatusTip("No Diffuse"); diffuse0Act->setCheckable(true); connect(diffuse0Act, SIGNAL(triggered()), this, SLOT(diffuse0())); diffuse1Act = new QAction("&Diffuse",this); diffuse1Act->setStatusTip("Diffuse"); diffuse1Act->setCheckable(true); connect(diffuse1Act, SIGNAL(triggered()), this, SLOT(diffuse1())); diffuseGroup = new QActionGroup(this); diffuseGroup->addAction(diffuse0Act); diffuseGroup->addAction(diffuse1Act); diffuse0Act->setChecked(true); //SPECULAR----------------------------------------------------- specular0Act = new QAction("&No Specular",this); specular0Act->setStatusTip("No Specular"); specular0Act->setCheckable(true); connect(specular0Act, SIGNAL(triggered()), this, SLOT(specular0())); specular1Act = new QAction("&Specular",this); specular1Act->setStatusTip("Specular"); specular1Act->setCheckable(true); connect(specular1Act, SIGNAL(triggered()), this, SLOT(specular1())); specularGroup = new QActionGroup(this); specularGroup->addAction(specular0Act); specularGroup->addAction(specular1Act); specular0Act->setChecked(true); //SPECULAR----------------------------------------------------- shininess0Act = new QAction("&No Shininess",this); shininess0Act->setStatusTip("No Shininess"); shininess0Act->setCheckable(true); connect(shininess0Act, SIGNAL(triggered()), this, SLOT(shininess0())); shininess1Act = new QAction("&Low Shininess",this); shininess1Act->setStatusTip("Low Shininess"); shininess1Act->setCheckable(true); connect(shininess1Act, SIGNAL(triggered()), this, SLOT(shininess1())); shininess2Act = new QAction("&High Shininess",this); shininess2Act->setStatusTip("High Shininess"); shininess2Act->setCheckable(true); connect(shininess2Act, SIGNAL(triggered()), this, SLOT(shininess2())); shininessGroup = new QActionGroup(this); shininessGroup->addAction(shininess0Act); shininessGroup->addAction(shininess1Act); shininessGroup->addAction(shininess2Act); shininess0Act->setChecked(true); //EMISSION----------------------------------------------------- emission0Act = new QAction("&No Emission",this); emission0Act->setStatusTip("No Emission"); emission0Act->setCheckable(true); connect(emission0Act, SIGNAL(triggered()), this, SLOT(emission0())); emission1Act = new QAction("&Emission",this); emission1Act->setStatusTip("eEmission"); emission1Act->setCheckable(true); connect(emission1Act, SIGNAL(triggered()), this, SLOT(emission1())); emissionGroup = new QActionGroup(this); emissionGroup->addAction(emission0Act); emissionGroup->addAction(emission1Act); emission0Act->setChecked(true); //SHADING------------------------------------------------- shading0Act = new QAction("&No shading", this); shading0Act->setStatusTip("No shading"); shading0Act->setCheckable(true); connect(shading0Act, SIGNAL(triggered()), this, SLOT(shading0())); shading1Act = new QAction("&Flat shading", this); shading1Act->setStatusTip("Flat shading"); shading1Act->setCheckable(true); connect(shading1Act, SIGNAL(triggered()), this, SLOT(shading1())); shading2Act = new QAction("&Smooth shading", this); shading2Act->setStatusTip("Smooth shading"); shading2Act->setCheckable(true); connect(shading2Act, SIGNAL(triggered()), this, SLOT(shading2())); shadingGroup = new QActionGroup(this); shadingGroup->addAction(shading0Act); shadingGroup->addAction(shading1Act); shadingGroup->addAction(shading2Act); shading0Act->setChecked(true); //NORMAL---------------------------------------------------- normal0Act = new QAction("&No normal",this); normal0Act->setStatusTip("No normal"); normal0Act->setCheckable(true); connect(normal0Act, SIGNAL(triggered()), this, SLOT(normal0())); normal1Act = new QAction("&normal",this); normal1Act->setStatusTip("Has normal"); normal1Act->setCheckable(true); connect(normal1Act, SIGNAL(triggered()), this, SLOT(normal1())); normalGroup = new QActionGroup(this); normalGroup->addAction(normal0Act); normalGroup->addAction(normal1Act); normal0Act->setChecked(true); }
int main(int argc, const char * argv[]) { // ========= Declare and initialize variables ========== BikeShed bike_shed; Color color1(4.5, 6.0 ,7.0); Color color2(0.0, 0.0, 3.0); Color color3(0.0, 8.4 ,0.0); Bike john_bike("John", color1); Bike jane_bike("Jane", color1); Bike sean_bike("Sean", color2); Bike andrea_bike("Andrea", color2); Bike peter_bike("Peter", color3); Bike mohammed_bike("Mohammed", color3); Bike hong_bike("Hong", color3); // ========= END Declare and initialize variables ========== // ========= Set the bike values of each person ========== john_bike.setBell(true); john_bike.setReflector(true); john_bike.setNLight(1); jane_bike.setBell(true); jane_bike.setNLight(2); sean_bike.setBell(true); sean_bike.setReflector(true); sean_bike.setNLight(7); andrea_bike.setBell(true); peter_bike.setBell(true); peter_bike.setReflector(true); mohammed_bike.setBell(true); mohammed_bike.setReflector(true); mohammed_bike.setNLight(3); hong_bike.setReflector(true); hong_bike.setNLight(20); // ========= END Set the bike values of each person ========== // ========= Performing different checks on the bikes ========== bike_shed.park(john_bike); std::cout << "Bikes in shed after John parks:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.park(jane_bike); std::cout << "Bikes in shed after Jane parks:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.park(sean_bike); std::cout << "Bikes in shed after Sean parks:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.park(andrea_bike); std::cout << "Bikes in shed after Andrea parks:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.park(peter_bike); std::cout << "Bikes in shed after Peter parks:" << "\n\n"; bike_shed.print(); std::cout << "\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; std::cout << "Illegal bikes:" << "\n\n"; bike_shed.checkLegal(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; std::cout << "Removing bikes:" << "\n\n"; bike_shed.remove("Peter", 1).print(); std::cout << "Bikes in shed after Peter's bike is removed:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.remove("John", 1).print(); std::cout << "Bikes in shed after John's bike is removed:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.remove("Andrea", 1).print(); std::cout << "Bikes in shed after Andrea's bike is removed:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.park(mohammed_bike); std::cout << "Bikes in shed after Mohammed parks:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; bike_shed.park(hong_bike); std::cout << "Bikes in shed after Hong parks:" << "\n\n"; bike_shed.print(); std::cout << "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" << "\n\n"; std::cout << "Remaining bikes:" << "\n\n"; bike_shed.print(); std::cout << "\n"; // ========= END Performing different checks on the bikes ========== return 0; }
void Check_Copter(Copter& copter) { bool Flag_1 = false; bool Flag_2 = false; Mat YUV; Mat color1(copter.height , copter.width , CV_8UC1); Mat color2(copter.height , copter.width , CV_8UC1); Mat color3(copter.height , copter.width , CV_8UC1); Mat color1_2(copter.height , copter.width , CV_8UC1); Mat color1_3(copter.height , copter.width , CV_8UC1); Mat color2_2(copter.height , copter.width , CV_8UC1); Mat color2_3(copter.height , copter.width , CV_8UC1); Mat Temp_roi; vector<vector<Point> > contours1; vector<vector<Point> > contours2; vector<vector<Point> > contours3; vector<Vec4i> hierarchy1; vector<Vec4i> hierarchy2; vector<Vec4i> hierarchy3; Rect copter_box1; Rect copter_box2; Rect copter_box3; Rect copter_box4; int max_contour1=0; int max_contour2=0; int max_contour3=0; int min_num1 =0x7fffff; int min_num2 =0x7fffff; int min_num3 =0x7fffff; int x1, x2, y1, y2; int min_diff =0x7fffff; int min_diff2 =0x7fffff; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; double start,end,t1; pthread_mutex_lock(&mutex); cvtColor(copter.Copter_Layer,YUV,CV_RGB2YCrCb); pthread_mutex_unlock(&mutex); vector<Mat> yuv; split(YUV,yuv); // start=(double)cvGetTickCount(); threshold(yuv[0],yuv[0],copter.Y_MAX,255,THRESH_TOZERO_INV); threshold(yuv[0],(color1),copter.Y_MIN,255,THRESH_BINARY); threshold(yuv[1],yuv[1],copter.Cb_MAX,255,THRESH_TOZERO_INV); threshold(yuv[1],(color1_2),copter.Cb_MIN,255,THRESH_BINARY); threshold(yuv[2],yuv[2],copter.Cr_MAX,255,THRESH_TOZERO_INV); threshold(yuv[2],(color1_3),copter.Cr_MIN,255,THRESH_BINARY); bitwise_and(color1,color1_2,color1_2); bitwise_and(color1_2,color1_3,color1); split(YUV,yuv); threshold(yuv[0],yuv[0],copter.Y_MAX2,255,THRESH_TOZERO_INV); threshold(yuv[0],(color2),copter.Y_MIN2,255,THRESH_BINARY); threshold(yuv[1],yuv[1],copter.Cb_MAX2,255,THRESH_TOZERO_INV); threshold(yuv[1],(color2_2),copter.Cb_MIN2,255,THRESH_BINARY); threshold(yuv[2],yuv[2],copter.Cr_MAX2,255,THRESH_TOZERO_INV); threshold(yuv[2],(color2_3),copter.Cr_MIN2,255,THRESH_BINARY); bitwise_and(color2,color2_2,color2_2); bitwise_and(color2_2,color2_3,color3); // end=(double)cvGetTickCount(); // t1 = (end-start)/((double)cvGetTickFrequency()*1000.); // printf("Threshold : %g ms\n",t1); #if DEBUG start=(double)cvGetTickCount(); #endif findContours(color1, contours1, hierarchy1, RETR_CCOMP, CHAIN_APPROX_TC89_KCOS); if(contours1.size() == 0 ) { cout <<copter.number <<": no color1 ! " << endl; } for(size_t idx = 0; idx < contours1.size(); idx++) { drawContours(color1,contours1,idx,Scalar(255,255,255),CV_FILLED,8); } bitwise_and(color1,color3,color2); findContours(color2, contours2,hierarchy2, RETR_CCOMP, CHAIN_APPROX_TC89_KCOS); if(contours2.size() == 0 ) { cout <<copter.number << ": no color2 ! " << endl; } #if DEBUG end=(double)cvGetTickCount(); t1 = (end-start)/((double)cvGetTickFrequency()*1000.); printf("findcountours : %g ms\n",t1); start=(double)cvGetTickCount(); #endif for(int m=0; m<contours1.size(); m++) { for(int n=0; n<contours2.size(); n++) {// copter_box1 = boundingRect(contours1[m]); copter_box2 = boundingRect(contours2[n]); Point box2_center = Point(copter_box2.x+(copter_box2.width/2),copter_box2.y+(copter_box2.height/2)); if(box2_center.x >=copter_box1.x-copter_box1.width && box2_center.x <= copter_box1.x+copter_box1.width*2 && box2_center.y >=copter_box1.y-copter_box1.height && box2_center.y <=copter_box1.y+(copter_box1.height)*2) { int diff = abs(copter_box2.x+(copter_box2.width/2) - copter_box1.x+(copter_box1.width/2)) + abs(copter_box2.y+(copter_box2.height/2) - copter_box1.y+(copter_box1.height/2)); if(diff < min_diff){ min_diff = diff; min_num1 = m; min_num2 = n; } } }// } absdiff(color3,color2,color3); findContours(color3, contours3, hierarchy3, RETR_CCOMP, CHAIN_APPROX_TC89_KCOS); if(contours1.size()>0 && contours3.size()>0 && min_num1 < contours1.size()) { copter_box4 = boundingRect(contours1[min_num1]); int centerof_box4_x = copter_box4.x + (copter_box4.width/2); int centerof_box4_y = copter_box4.y + (copter_box4.height/2); int centerof_box3_x=0; int centerof_box3_y=0; for(int t=0; t<contours3.size(); t++) { bool check_exception=true; copter_box3 = boundingRect(contours3[t]); centerof_box3_x = copter_box3.x + (copter_box3.width/2); centerof_box3_y = copter_box3.y + (copter_box3.height/2); if(centerof_box3_x >= copter_box4.x && centerof_box3_x <= copter_box4.x+copter_box4.width && centerof_box3_y >= copter_box4.y && centerof_box3_y <= copter_box4.y+copter_box4.height) { check_exception = false; } if(check_exception && contours3[t].size() < contours1[min_num1].size() && t != min_num2 ) { int diff = abs(centerof_box4_x - centerof_box3_x) + abs(centerof_box4_y - centerof_box3_y); if(diff<min_diff2){ min_diff2 = diff; min_num3 = t; } } } if(min_num3 <contours3.size()) { copter_box3 = boundingRect(contours3[min_num3]); copter.Head_vector = Return_HeadWay(copter_box3, copter_box4); } } #if DEBUG cout << "Copter.Head_Vector : " << copter.Head_vector << endl; #endif #if DEBUG end=(double)cvGetTickCount(); t1 = (end-start)/((double)cvGetTickFrequency()*1000.); printf("for loop : %g ms\n",t1); start =(double)cvGetTickCount(); #endif if(min_diff > 10000) { copter.not_found_count++; switch(copter.vector) { case 1 : copter.width += (copter.width>>1); //cout << copter.number << " : 1 " << endl; break; case 2 : copter.width += (copter.width>>1); copter.y -= (copter.height>>1); copter.height += (copter.height>>1); //cout << copter.number << " : 2 " << endl; break; case 3 : copter.y -= (copter.height>>1); copter.height += (copter.height>>1); //cout << copter.number << " : 3 "<< endl; break; case 4 : copter.x -= (copter.width>>1); copter.width +=(copter.width>>1); copter.y -= (copter.height>>1); copter.height += (copter.height>>1); //cout << copter.number << " : 4 "<< endl; break; case 5 : copter.x -= (copter.width>>1); copter.width += (copter.width>>1); //cout << copter.number << " : 5 "<< endl; break; case 6 : copter.x -= (copter.width>>1); copter.width += (copter.width>>1); copter.height += (copter.height>>1); //cout << copter.number << " : 6 "<< endl; break; case 7 : copter.height += (copter.height>>1); //cout << copter.number << " : 7 "<< endl; break; case 8 : copter.height += (copter.height>>1); copter.width += (copter.width>>1); //cout << copter.number << " : 8 "<< endl; break; default : break; } Reposition_minus(copter); if(copter.not_found_count >=FIND_THRESHOLD) { copter.not_found_count = 0 ; copter.Flag = false; } return; }//확인요망
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Color4ub::Color4ub(Color3::ColorIdent colorIdent) { Color3ub color3(colorIdent); set(color3.r(), color3.g(), color3.b(), 255); }
/** The ColorMap constructor defines many hardcoded RGB values that are used during segmentation. The most important of these with respect to inputs * are the STEM_COLOR, BORDER_COLOR, UNSEGMENTED_COLOR. The remainders correspond to leaves. If a hand-segmented or machine learning segmented plant * is provided and colors don't correspond to these values, behavior will likely be unexpected. */ ColorMap::ColorMap() { TupleTriplet STEM_COLOR(0.0, 255.0, 255.0); TupleTriplet BORDER_COLOR(80.0, 80.0, 80.0); TupleTriplet UNSEGMENTED_COLOR(255.0, 255.0, 255.0); TupleTriplet DEBUG_COLOR(255.0, 20.0, 147.0); TupleTriplet INFLORESCENCE_COLOR(255.0, 215.0, 0.0); // gold _stem_color = STEM_COLOR; _border_color = BORDER_COLOR; _unsegmented_color = UNSEGMENTED_COLOR; _debug_color = DEBUG_COLOR; _inflorescence_color = INFLORESCENCE_COLOR; // We're emulating the ggplot2 colors. // http://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette // and converted the hex to rgb TupleTriplet color1(248.0, 118.0, 109.0); //salmon-y #F8766D TupleTriplet color2(183.0, 159.0, 0.0); //tan-y #B79F00 TupleTriplet color3(0.0, 186.0, 56.0); //green-y #00BA38 //TupleTriplet color4(0.0, 191.0, 196.0); //sea-green-y #00BFC4 TupleTriplet color4(0.0, 134.0, 125.0); //sea-green-y TupleTriplet color5(97.0, 156.0, 255.0); // sky blue-y #619CFF TupleTriplet color6(245.0, 100.0, 227.0); // pink-y #F564E3 TupleTriplet color7(229.0, 135.0, 0.0); //orange-y #E58700 TupleTriplet color8(185.0, 131.0, 255.0); // purple-y #B983FF TupleTriplet color9(222.0, 42.0, 29.0); // red-ish TupleTriplet color10(222.0, 29.0, 186.0); TupleTriplet color11(103.0, 29.0, 222.0); TupleTriplet color12(20.0, 42.0, 222.0); /* TupleTriplet color5(29.0, 135.0, 222.0); TupleTriplet color6(29.0, 222.0, 96.0); TupleTriplet color7(148.0, 222.0, 29.0); TupleTriplet color8(222.0, 125.0, 29.0); TupleTriplet color9(240.0, 178.0, 179.0); TupleTriplet color10(176.0, 237.0, 161.0); TupleTriplet color11(250.0, 250.0, 17.0); TupleTriplet color12(247.0, 168.0, 229.0); */ //New colors added to account for manual segmentation TupleTriplet color13(150.0, 150.0, 150.0); TupleTriplet color14(0.0, 0.0, 255.0); TupleTriplet color15(170.0, 170.0, 255.0); TupleTriplet color16(255.0, 0.0, 0.0); TupleTriplet color17(255.0, 0.0, 127.0); TupleTriplet color18(0.0, 170.0, 0.0); TupleTriplet color19(85.0, 170.0, 255.0); TupleTriplet color20(255.0, 170.0, 0.0); TupleTriplet color21(153.0, 102.0, 51.0); TupleTriplet color22(255.0, 170.0, 255.0); TupleTriplet color23(170.0, 255.0, 127.0); TupleTriplet color24(255.0, 255.0, 127.0); TupleTriplet color25(108.0, 108.0, 108.0); TupleTriplet color26(237.0, 146.0, 15.0); TupleTriplet color27(170.0, 255.0, 0.0); _leafColorMap.insert(std::pair<int, TupleTriplet> (1, color1)); _leafColorMap.insert(std::pair<int, TupleTriplet> (2, color2)); _leafColorMap.insert(std::pair<int, TupleTriplet> (3, color3)); _leafColorMap.insert(std::pair<int, TupleTriplet> (4, color4)); _leafColorMap.insert(std::pair<int, TupleTriplet> (5, color5)); _leafColorMap.insert(std::pair<int, TupleTriplet> (6, color6)); _leafColorMap.insert(std::pair<int, TupleTriplet> (7, color7)); _leafColorMap.insert(std::pair<int, TupleTriplet> (8, color8)); _leafColorMap.insert(std::pair<int, TupleTriplet> (9, color9)); _leafColorMap.insert(std::pair<int, TupleTriplet> (10, color10)); _leafColorMap.insert(std::pair<int, TupleTriplet> (11, color11)); _leafColorMap.insert(std::pair<int, TupleTriplet> (12, color12)); _leafColorMap.insert(std::pair<int, TupleTriplet> (13, color13)); _leafColorMap.insert(std::pair<int, TupleTriplet> (14, color14)); _leafColorMap.insert(std::pair<int, TupleTriplet> (15, color15)); _leafColorMap.insert(std::pair<int, TupleTriplet> (16, color16)); _leafColorMap.insert(std::pair<int, TupleTriplet> (17, color17)); _leafColorMap.insert(std::pair<int, TupleTriplet> (18, color18)); _leafColorMap.insert(std::pair<int, TupleTriplet> (19, color19)); _leafColorMap.insert(std::pair<int, TupleTriplet> (20, color20)); _leafColorMap.insert(std::pair<int, TupleTriplet> (21, color21)); _leafColorMap.insert(std::pair<int, TupleTriplet> (22, color22)); _leafColorMap.insert(std::pair<int, TupleTriplet> (23, color23)); _leafColorMap.insert(std::pair<int, TupleTriplet> (24, color24)); _leafColorMap.insert(std::pair<int, TupleTriplet> (25, color25)); _leafColorMap.insert(std::pair<int, TupleTriplet> (26, color26)); _leafColorMap.insert(std::pair<int, TupleTriplet> (27, color27)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color1, 1)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color2, 2)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color3, 3)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color4, 4)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color5, 5)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color6, 6)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color7, 7)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color8, 8)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color9, 9)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color10, 10)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color11, 11)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color12, 12)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color13, 13)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color14, 14)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color15, 15)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color16, 16)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color17, 17)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color18, 18)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color19, 19)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color20, 20)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color21, 21)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color22, 22)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color23, 23)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color24, 24)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color25, 25)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color26, 26)); _leafColorMap_colorsToLabel.insert(std::pair<TupleTriplet, int> (color27, 27)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color1, 1)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color2, 2)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color3, 3)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color4, 4)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color5, 5)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color6, 6)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color7, 7)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color8, 8)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color9, 9)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color10, 10)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color11, 11)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color12, 12)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color13, 13)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color14, 14)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color15, 15)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color16, 16)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color17, 17)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color18, 18)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color19, 19)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color20, 20)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color21, 21)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color22, 22)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color23, 23)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color24, 24)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color25, 25)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color26, 26)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (color27, 27)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (STEM_COLOR, 28)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (BORDER_COLOR, 29)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (UNSEGMENTED_COLOR, 30)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (DEBUG_COLOR, 31)); _map_explicitlyHandledColors.insert(std::pair<TupleTriplet, int> (INFLORESCENCE_COLOR, 32)); }