map<string, string> CKadScript::ReadHeader(const string& Source) { map<string, string> HeaderFields; string::size_type HeaderBegin = Source.find("/*"); string::size_type HeaderEnd = Source.find("*/"); if(HeaderBegin == -1 || HeaderEnd == -1) return HeaderFields; vector<string> HeaderLines = SplitStr(Source.substr(HeaderBegin + 2, HeaderEnd - (HeaderBegin + 2)), "\n"); for(size_t i=0; i < HeaderLines.size(); i++) { string Line = Trimm(HeaderLines.at(i)); if(Line.substr(0,1) == "*") { Line.erase(0,1); Line = Trimm(Line); } pair<string,string> Field = Split2(Line, ":"); if(Field.first.empty() || Field.first.find(" ") != string::npos) continue; HeaderFields[Field.first] = Trimm(Field.second); } return HeaderFields; }
uint32 CKadScript::GetVersion(const wstring& sVersion) { uint32 Version = 0; vector<wstring> Ver = SplitStr(sVersion,L"."); for(size_t i = 0; i < Min(sizeof(uint32), Ver.size()); i++) ((byte*)&Version)[sizeof(uint32)-(i+1)] = wstring2int(Ver[i]); return Version; }
int ObjectDetection::test(std::string imgName) { std::vector<std::string> strs; // boost::split(strs, imgName, boost::is_any_of(" ") ); SplitStr(imgName, ' ', strs); if( strs.empty() == true ) return -1; std::string imgStr = strs[0]; cv::Mat img = cv::imread(imgStr.c_str()); if(img.data == NULL) return -1; std::vector<cv::Rect> found, found_filtered; long sz = m_phog->getDescriptorSize(); // run the detector with default parameters. to get a higher hit-rate // (and more false alarms, respectively), decrease the hitThreshold and // groupThreshold (set groupThreshold to 0 to turn off the grouping completely). //m_phog->detectMultiScale(img, found, 0, Size(16,16), Size(0, 0), 1.05, 0); #if 0 m_phog->detectMultiScale(img, found, 0.47, cv::Size(8,8), cv::Size(32,32), 1.05, 2); cv::namedWindow("object detector", 1); size_t i, j; for( i = 0; i < found.size(); i++ ) { cv::Rect r = found[i]; for( j = 0; j < found.size(); j++ ) if( j != i && (r & found[j]) == r) break; if( j == found.size() ) found_filtered.push_back(r); } for( i = 0; i < found_filtered.size(); i++ ) { cv::Rect r = found_filtered[i]; // the HOG detector returns slightly larger rectangles than the real objects. // so we slightly shrink the rectangles to get a nicer output. r.x += cvRound(r.width*0.1); r.width = cvRound(r.width*0.8); r.y += cvRound(r.height*0.07); r.height = cvRound(r.height*0.8); cv::rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 3); } cv::imshow("object detector", img); int c = cv::waitKey(0) & 255; #endif #if 1 double prob = 0.0; // int classification = testClassify(img, prob); testClassifyMultiScale(img, 16, prob); cout<<"Classified: " << prob <<endl; #endif return 0; }
bool CDexFun::StrToD3DVector3(string str, D3DXVECTOR3& vec, char split_char) { std::vector<string> str_arr; SplitStr(str, split_char, str_arr); DEX_ENSURE_B(str_arr.size() == 3); vec.x = atof(str_arr[0].c_str()); vec.y = atof(str_arr[1].c_str()); vec.z = atof(str_arr[2].c_str()); return true; }
void Unreal3DExport::RegisterMaterial( IGameNode* node, IGameMesh* mesh, FaceEx* f, FJSMeshTri* tri ) { tri->TextureNum = f->matID; int matid = f->matID; IGameMaterial* mat = mesh->GetMaterialFromFace(f); if( mat ) { Tab<TSTR*> tokens = TokStr(mat->GetMaterialName(),_T(" \t,;")); for( int i=0; i!=tokens.Count(); ++i ) { if( MatchPattern(*tokens[i],TSTR(_T("F=*")),TRUE) ) { SplitStr(*tokens[i],_T('=')); tri->Flags = static_cast<byte>(_ttoi(tokens[i]->data())); } } tokens.Delete(0,tokens.Count()); if( Materials.Count() <= matid ) { Materials.Append(matid-Materials.Count()+1,&sMaterial::DefaultMaterial); } if( Materials[matid].Mat != mat ) { Materials[matid].Mat = mat; } /*for( int i=0; i!=mat->GetSubMaterialCount(); ++i ) { IGameMaterial* sub = mat->GetSubMaterial(i); if( sub ) { TSTR matname = sub->GetMaterialName(); int subid = mat->GetMaterialID(i); int x = 0; } }*/ } }
int ProxyProtocolHandler::ParseProxyHeaderV1(const char * hdr, int read_size) { const char * end = (const char *) memchr(hdr, '\r', read_size - 1); int size = end - hdr + 2; if (!end || *(end + 1) != '\n') { return -__LINE__; } std::vector<std::string> tokens = SplitStr(std::string(hdr, end), " "); if (tokens[1] == "UNKNOWN") { return size; } if (tokens.size() != 6) { return -__LINE__; } const std::string & src_ip = tokens[2]; const std::string & dst_ip = tokens[3]; int src_port = atoi(tokens[4].c_str()); int dst_port = atoi(tokens[5].c_str()); if (src_port < 0 || src_port > 65535 || dst_port < 0 || dst_port > 65535) { return -__LINE__; } if (tokens[1] == "TCP4") { if (SetAddr(src_ip.c_str(), src_port, (struct sockaddr_in &) src_addr_) != 0) { return -__LINE__; } if (SetAddr(dst_ip.c_str(), dst_port, (struct sockaddr_in &) dst_addr_) != 0) { return -__LINE__; } } else if (tokens[1] == "TCP6") { if (SetAddr6(src_ip.c_str(), src_port, (struct sockaddr_in6 &) src_addr_) != 0) { return -__LINE__; } if (SetAddr6(dst_ip.c_str(), dst_port, (struct sockaddr_in6 &) dst_addr_) != 0) { return -__LINE__; } } return size; }
int ObjectDetection::trainMultiScale(std::string imgName, bool classType) { int stride = 32; // get the bounding box too if there // format of line - imageName #objs=1 x y x_width y_width // split std::vector<std::string> strs; // boost::split(strs, imgName, boost::is_any_of(" ") ); SplitStr(imgName, ' ', strs); if( strs.empty() == true ) return -1; std::string imgStr = strs[0]; cv::Mat img = cv::imread(imgStr.c_str()); if(img.data == NULL) return -1; int ht = img.rows; int wid = img.cols; if( 4*ht < 3*m_winHt || 4*wid < 3*m_winWid ) { return 0; } // bounding box int x_left = 0, y_left = 0, x_wid = wid, y_ht = ht; if(strs.size() >= 6) { x_left = atoi(strs[2].c_str()); y_left = atoi(strs[3].c_str()); x_wid = atoi(strs[4].c_str()); y_ht = atoi(strs[5].c_str()); } if( 4*y_ht < 3*m_winHt || 4*x_wid < 3*m_winWid ) { return 0; } cv::Rect roi(x_left, y_left, x_wid, y_ht); //cv::Mat boundedImg = cvCreateImage(cvGetSize(&img), img->depth, img->nChannels); cv::Mat boundedImg = cv::Mat(img, roi); if(classType == 0) { // multiscale training on negative dataset for(int x = 0; x < wid; x += stride) { for(int y = 0; y < ht; y += stride) { if( (x + m_winWid) > wid || (y + m_winHt) > ht) continue; // detect cv::Mat blockImg = boundedImg(cv::Range(y,y+m_winHt), cv::Range(x, x+m_winWid)); this->train(blockImg, classType); } } } else { // image resize cv::Size sz(m_winWid, m_winHt); cv::resize(boundedImg, boundedImg, sz, 0, 0, cv::INTER_LINEAR); ht = m_winHt; wid = m_winWid; /* cv::imshow("object detector", boundedImg); int c = cv::waitKey(0) & 255; */ this->train(boundedImg, classType); } return 0; }
/** \brief *创建银联处理线程 * \param cIp IP地址 * \param cPort 端口集 * \return true:成功,false:失败 */ bool SimplexSock::YinLianThread(const char* cIpPort) { try{ if(!cIpPort) return false; /**< 分离单工对 */ vector<string> vecSimplex; trace_log(DBG,"cIpPort[%s]",cIpPort); SplitStr(cIpPort,";",vecSimplex); if(0==vecSimplex.size()) { trace_log(ERR,"Split cIpPort Error!"); return false; } vector<string>::iterator it; for(it=vecSimplex.begin();it!=vecSimplex.end();it++) { /**< 分离单工对参数*/ vector<string> vecTmp; int nPort=0,nListenPort=0; trace_log(DBG,"Simplex[%s]",(*it).c_str()); SplitStr((*it).c_str(),",",vecTmp); if(nMaxConn>=8) return true; if(3!=vecTmp.size()) { continue; } nPort=atoi(vecTmp[1].c_str()); nListenPort=atoi(vecTmp[2].c_str()); if(nPort<1024||nPort>65535||nListenPort<1024||nListenPort>65535) { continue; } /**< 设置单工参数 */ PSIMPLEX_DESC pDesc=new SIMPLEX_DESC(); if(!pDesc) { trace_log(ERR,"new DESC ERROR"); continue; } trace_log(DBG,"cIp=%s nPort=%d,nListenPort=%d",vecTmp[0].c_str(),nPort,nListenPort); memset(pDesc,0,sizeof(SIMPLEX_DESC)); memcpy(pDesc->cIp,vecTmp[0].c_str(),vecTmp[0].length()); pDesc->nPort=nPort; pDesc->nListenPort=nListenPort; pDesc->nMask=0; pDesc->socket_Snddesc=0; pDesc->socket_Recdesc=0; pDesc->tSndIdle=time(0); pDesc->tRecIdle=time(0); pDesc->pSimp=this; /**< 单工接收线路线程 */ pthread_attr_t attr; pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); pthread_create(&pDesc->thrdRecID, &attr, YinLianRecPro,pDesc); /**< 单工发送线路线程 */ pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); pthread_create(&pDesc->thrdSndID, &attr, YinLianSndPro,pDesc); pthread_attr_destroy(&attr); nMaxConn++; trace_log(DBG,"Curr nMax[%d]",nMaxConn); } return true; }catch(...){ trace_log(ERR,"Error in ClientYinLian::YinLianThread()"); return false; } }
void Unreal3DExport::WriteScript() { // Write script file { fScript = _tfopen(ScriptFileName,_T("wb")); if( !fScript ) { ProgressMsg.printf(GetString(IDS_ERR_FSCRIPT),ScriptFileName); throw MAXException(ProgressMsg.data()); } TSTR buf; // Write class def _ftprintf( fScript, _T("class %s extends Object;\n\n"), FileName ); // write import _ftprintf( fScript, _T("#exec MESH IMPORT MESH=%s ANIVFILE=%s_a.3D DATAFILE=%s_d.3D \n"), FileName, FileName, FileName ); // write origin & rotation // TODO: figure out why it's incorrect without -1 Point3 porg = OptOffset * OptScale * -1; _ftprintf( fScript, _T("#exec MESH ORIGIN MESH=%s X=%f Y=%f Z=%f PITCH=%d YAW=%d ROLL=%d \n"), FileName, porg.x, porg.y, porg.z, (int)OptRot.x, (int)OptRot.y, (int)OptRot.z ); // write mesh scale Point3 psc( Point3(1.0f/OptScale.x,1.0f/OptScale.y,1.0f/OptScale.z)); _ftprintf( fScript, _T("#exec MESH SCALE MESH=%s X=%f Y=%f Z=%f \n"), FileName, psc.x, psc.y, psc.z ); // write meshmap _ftprintf( fScript, _T("#exec MESHMAP NEW MESHMA=P%s MESH=%smap \n"), FileName, FileName ); // write meshmap scale _ftprintf( fScript, _T("#exec MESHMAP SCALE MESHMAP=%s X=%f Y=%f Z=%f \n"), FileName, psc.x, psc.y, psc.z ); // write sequence _ftprintf( fScript, _T("#exec MESH SEQUENCE MESH=%s SEQ=%s STARTFRAME=%d NUMFRAMES=%d \n"), FileName, _T("All"), 0, FrameCount-1 ); // Get World NoteTrack ReferenceTarget *rtscene = pInt->GetScenePointer(); for( int t=0; t<rtscene->NumNoteTracks(); ++t ) { DefNoteTrack* notetrack = static_cast<DefNoteTrack*>(rtscene->GetNoteTrack(t)); for( int k=0; k<notetrack->keys.Count(); ++k ) { NoteKey* notekey = notetrack->keys[k]; TSTR text = notekey->note; int notetime = notekey->time / pScene->GetSceneTicks(); while( !text.isNull() ) { TSTR cmd = SplitStr(text,_T('\n')); if( MatchPattern(cmd,TSTR(_T("a *")),TRUE) ) { SplitStr(cmd,_T(' ')); TSTR seq = SplitStr(cmd,_T(' ')); int end = _ttoi(SplitStr(cmd,_T(' ')));; TSTR rate = SplitStr(cmd,_T(' ')); TSTR group = SplitStr(cmd,_T(' ')); if( seq.isNull() ) { ProgressMsg.printf(_T("Missing animation name in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } if( end <= notetime ) { ProgressMsg.printf(_T("Invalid animation endframe (%d) in notekey #%d"),end,notetime); throw MAXException(ProgressMsg.data()); } int startframe = notetime; int numframes = end - notetime; buf.printf( _T("#exec MESH SEQUENCE MESH=%s SEQ=%s STARTFRAME=%d NUMFRAMES=%d"), FileName, seq, notetime, numframes ); if( !rate.isNull() ) buf.printf( _T("%s RATE=%f"), buf, rate ); if( !group.isNull() ) buf.printf( _T("%s GROUP=%f"), buf, rate ); SeqName = seq; SeqFrame = startframe; buf.printf( _T("%s \n"), buf ); _fputts( buf, fScript ); } else if( MatchPattern(cmd,TSTR(_T("n *")),TRUE) ) { SplitStr(cmd,_T(' ')); TSTR func = SplitStr(cmd,_T(' ')); TSTR time = SplitStr(cmd,_T(' ')); if( func.isNull() ) { ProgressMsg.printf(_T("Missing notify name in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } if( time.isNull() ) { ProgressMsg.printf(_T("Missing notify time in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } buf.printf( _T("#exec MESH NOTIFY MESH=%s SEQ=%s TIME=%s FUNCTION=%s"), FileName, SeqName, time, func ); _fputts( buf, fScript ); } } } } // TODO: write materials if( Materials.Count() > 0 ) { for( int i=0; i<Materials.Count(); ++i ) { IGameMaterial* mat = Materials[i].Mat; if( mat == NULL ) continue; _ftprintf( fScript, _T("#exec MESHMAP SETTEXTURE MESHMAP=%s NUM=%d TEXTURE=%s \n"), FileName, i, _T("DefaultTexture") ); } } } }