static void run( const char *input, const char *output ) { Huint i; Huint j; image *img; clock_t start; clock_t end; double ela; double bytes; double bandw; img = read_png_file( input ); start = clock(); send_image( img ); recv_image( img ); end = clock(); write_png_file( output, img ); ela = (double)(end - start); ela /= 2405516000.0; bytes = LOOPS * DATA * 8.0; bandw = bytes / ela; printf( "Processed %.2f bytes of data in %.2f seconds\n", bytes, ela ); printf( "Bandwidth: %.2f bytes/sec\n", bandw ); }
void CmdTCPConnection<CmdClass>::send_image(util::Image &img) { std::shared_ptr<std::vector<unsigned char>> imgbuf = std::make_shared<std::vector<unsigned char>>(); cv::imencode(".jpg", img.getImage(), *imgbuf); return send_image(imgbuf, "jpg"); }
/*void Read() { start(); send_byte(0xA0); aknowledge(); send_byte(0x00); aknowledge(); send_byte(0x00); aknowledge(); start(); send_byte(0xA1); //device address aknowledge(); a=read_byte(); aknowledge(); b=read_byte(); aknowledge(); c=read_byte(); aknowledge(); d=read_byte(); aknowledge(); e=read_byte(); aknowledge(); f=read_byte(); noack(); stop(); } */ void main() { temp=0; send_image(0x2C, 0x00); //send64(0x00, 0x80, array, 128); //Read(); //P1 = b; while(1) { } }
void csWebView::SendToCGLX() { //printf("Hello at x: %d y: %d\n", hit_pos.x(), hit_pos.y()); QWebFrame *tframe=page()->currentFrame (); QWebHitTestResult hitresult = tframe->hitTestContent ( hit_pos ); if(!hitresult.isNull()) { QPixmap img = hitresult.pixmap(); if(!img.isNull()) { //printf("Width: %d Height: %d Link: %s\n",img.width(), img.height(),hitresult.imageUrl().toString().toStdString().c_str()); emit send_image(img.width(), img.height() , hitresult.imageUrl()); } } }
int handle_pending_logins() { while (pending_login_users_.size() > 0) { player_ptr pp; if(!pending_login_users_.pop_front(pp)) break; auto itp = online_players.find(pp->uid_); if (itp == online_players.end() ){ online_players.insert(std::make_pair(pp->uid_, pp)); } //如果用户已在线 else{ msg_same_account_login msg; auto conn = itp->second->from_socket_.lock(); if (conn == pp->from_socket_.lock()){ return error_success; } if(conn.get()) send_msg(conn, msg, true); replace_map_v(online_players, std::make_pair(pp->uid_, pp)); } auto pconn = pp->from_socket_.lock(); if (pconn.get()){ pconn->is_login_ = false; send_all_game_to_player(pconn); msg_user_login_ret msg; response_user_login(pp, pconn, msg); msg_user_image msg_headpic; COPY_STR(msg_headpic.uid_, pp->uid_.c_str()); send_image(msg_headpic, pp->head_ico_, pconn); } } return 0; }
int handle_get_verify_code(msg_get_verify_code* pverify) { std::string sql = "call random_select_verify_code(8);"; Database& db = *db_; Query q(db); if (!q.get_result(sql)){ return error_success; } vector<vector<char>> anwsers; vector<char> image, image2, tmp_iamge; msg_verify_code msg; int rows = q.num_rows(); int ans = rand_r(rows - 1); int i = 0; //混淆答案 while (q.fetch_row()) { if (i == ans){ COPY_STR(msg.question_, q.getstr()); q.getblob("image", image); q.getblob("image2", image2); } else{ q.getstr(); tmp_iamge.clear(); q.getblob("image", tmp_iamge); if (!tmp_iamge.empty()){ anwsers.push_back(tmp_iamge); } tmp_iamge.clear(); q.getblob("image2", tmp_iamge); if (!tmp_iamge.empty()){ anwsers.push_back(tmp_iamge); } } i++; } send_msg(pverify->from_sock_, msg); std::random_shuffle(anwsers.begin(), anwsers.end()); int index = -1; if (!image.empty()){ index = rand_r(std::min<int>(7, anwsers.size() - 1)); anwsers.insert(anwsers.begin() + index, image); } int index2 = -1; if (!image2.empty()){ index2 = rand_r(std::min<int>(7, anwsers.size() - 1)); anwsers.insert(anwsers.begin() + index2, image2); //如果插在前一副图的前面,则前面一副图的index+1 if (index2 <= index){ index++; } } for (int i = 0; i < (int)anwsers.size() && i < 8; i++) { vector<char>& img = anwsers[i]; msg_image_data msg_img; msg_img.this_image_for_ = -2; send_image(msg_img, img, pverify->from_sock_); } std::string vc; if (index >= 0) vc += boost::lexical_cast<std::string>(index) + ","; if (index2 >= 0) vc += boost::lexical_cast<std::string>(index2) + ","; pverify->from_sock_->verify_code_.store(vc); return error_success; }
int main(int argc, char **argv) { int res; try { socket.bind ("tcp://*:14444"); s_sendmore (socket, "event"); s_send (socket, "{type:\"up\"}"); } catch (zmq::error_t e) { cerr << "Cannot bind to socket: " <<e.what() << endl; return -1; } // printf("Kinect camera test\n"); // // int i; // for (i=0; i<2048; i++) { // float v = i/2048.0; // v = powf(v, 3)* 6; // t_gamma[i] = v*6*256; // } // // g_argc = argc; // g_argv = argv; // // //setup Freenect... // if (freenect_init(&f_ctx, NULL) < 0) { // printf("freenect_init() failed\n"); // return 1; // } // // freenect_set_log_level(f_ctx, FREENECT_LOG_ERROR); // // int nr_devices = freenect_num_devices (f_ctx); // printf ("Number of devices found: %d\n", nr_devices); // // int user_device_number = 0; // if (argc > 1) // user_device_number = atoi(argv[1]); // // if (nr_devices < 1) // return 1; // // if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) { // printf("Could not open device\n"); // return 1; // } // // freenect_set_tilt_degs(f_dev,freenect_angle); // freenect_set_led(f_dev,LED_RED); // freenect_set_depth_callback(f_dev, depth_cb); // freenect_set_video_callback(f_dev, rgb_cb); // freenect_set_video_format(f_dev, FREENECT_VIDEO_RGB); // freenect_set_depth_format(f_dev, FREENECT_DEPTH_11BIT); // // freenect_start_depth(f_dev); // freenect_start_video(f_dev); initFreenect(); //start the freenect thread to poll for events res = pthread_create(&ocv_thread, NULL, freenect_threadfunc, NULL); if (res) { printf("pthread_create failed\n"); return 1; } Mat depthf; Mat frameMat(rgbMat); Mat blobMaskOutput(frameMat.size(),CV_8UC1), outC(frameMat.size(),CV_8UC3); Mat prevImg(frameMat.size(),CV_8UC1), nextImg(frameMat.size(),CV_8UC1), prevDepth(depthMat.size(),CV_8UC1); vector<Point2f> prevPts,nextPts; vector<uchar> statusv; vector<float> errv; Rect cursor(frameMat.cols/2,frameMat.rows/2,10,10); bool update_bg_model = true; int fr = 1; int register_ctr = 0,register_secondbloc_ctr = 0; bool registered = false; Point2i appear(-1,-1); double appearTS = -1; Point2i midBlob(-1,-1); Point2i lastMove(-1,-1); int hcr_ctr = -1; vector<int> hc_stack(20); int hc_stack_ptr = 0; while (!die) { fr++; // imshow("rgb", rgbMat); pthread_mutex_lock(&buf_mutex); //Linear interpolation { Mat _tmp = (depthMat - 400.0); //minimum observed value is ~440. so shift a bit _tmp.setTo(Scalar(2048), depthMat > ((!registered) ? 700.0 : 750.0)); //cut off at 600 to create a "box" where the user interacts _tmp.convertTo(depthf, CV_8UC1, 255.0/1648.0); //values are 0-2048 (11bit), account for -400 = 1648 } { Mat _tmp; depthMat.convertTo(_tmp, CV_8UC1, 255.0/2048.0); cvtColor(_tmp, outC, CV_GRAY2BGR); } pthread_mutex_unlock(&buf_mutex); // { //saving the frames to files for debug // stringstream ss; ss << "depth_"<<fr<<".png"; // imwrite(ss.str(), depthf); // } //Logarithm interpolation - try it!, It should be more "sensitive" for closer depths // { // Mat tmp,tmp1; // depthMat.convertTo(tmp, CV_32FC1); // log(tmp,tmp1); // tmp1.convertTo(depthf, CV_8UC1, 255.0/7.6246189861593985); // } // imshow("depth",depthf); Mat blobMaskInput = depthf < 255; //anything not white is "real" depth vector<Point> ctr,ctr2; Scalar blb = refineSegments(Mat(),blobMaskInput,blobMaskOutput,ctr,ctr2,midBlob); //find contours in the foreground, choose biggest imshow("first", blobMaskOutput); /////// blb : //blb[0] = x, blb[1] = y, blb[2] = 1st blob size, blb[3] = 2nd blob size. // uint mode_counters[3] = {0}; if(blb[0]>=0 && blb[2] > 500) { //1st blob detected, and is big enough //cvtColor(depthf, outC, CV_GRAY2BGR); //closest point to the camera Point minLoc; double minval,maxval; minMaxLoc(depthf, &minval, &maxval, &minLoc, NULL, blobMaskInput); circle(outC, minLoc, 5, Scalar(0,255,0), 3); Scalar mn,stdv; meanStdDev(depthf,mn,stdv,blobMaskInput); //cout << "min: " << minval << ", max: " << maxval << ", mean: " << mn[0] << endl; blobMaskInput = depthf < (mn[0] + stdv[0]*.5); blb = refineSegments(Mat(),blobMaskInput,blobMaskOutput,ctr,ctr2,midBlob); imshow("second", blobMaskOutput); if(blb[0] >= 0 && blb[2] > 300) { //draw contour Scalar color(0,0,255); for (int idx=0; idx<ctr.size()-1; idx++) line(outC, ctr[idx], ctr[idx+1], color, 1); line(outC, ctr[ctr.size()-1], ctr[0], color, 1); if(ctr2.size() > 0) { Scalar color2(255,0,255); for (int idx=0; idx<ctr2.size()-1; idx++) line(outC, ctr2[idx], ctr2[idx+1], color2, 2); line(outC, ctr2[ctr2.size()-1], ctr2[0], color2, 2); } //draw "major axis" // Vec4f _line; Mat curve(ctr); // fitLine(curve, _line, CV_DIST_L2, 0, 0.01, 0.01); // line(outC, Point(blb[0]-_line[0]*70,blb[1]-_line[1]*70), // Point(blb[0]+_line[0]*70,blb[1]+_line[1]*70), // Scalar(255,255,0), 1); //blob center circle(outC, Point(blb[0],blb[1]), 50, Scalar(255,0,0), 3); // cout << "min depth " << minval << endl; register_ctr = MIN((register_ctr + 1),60); if(blb[3] > 5000) register_secondbloc_ctr = MIN((register_secondbloc_ctr + 1),60); if (register_ctr > 30 && !registered) { registered = true; appear.x = -1; update_bg_model = false; lastMove.x = blb[0]; lastMove.y = blb[1]; cout << "blob size " << blb[2] << endl; if(register_secondbloc_ctr < 30) { if(blb[2] > 10000) { cout << "register panner" << endl; send_event("Register", "\"mode\":\"openhand\""); } else { cout << "register pointer" << endl; send_event("Register", "\"mode\":\"theforce\""); } } else { cout << "register tab swithcer" << endl; send_event("Register", "\"mode\":\"twohands\""); } } if(registered) { stringstream ss; ss << "\"x\":" << (int)floor(blb[0]*100.0/640.0) << ",\"y\":" << (int)floor(blb[1]*100.0/480.0) << ",\"z\":" << (int)(mn[0] * 2.0); //cout << "move: " << ss.str() << endl; send_event("Move", ss.str()); //---------------------- fist detection --------------------- //calc laplacian of curve vector<Point> approxCurve; //approximate curve approxPolyDP(curve, approxCurve, 10.0, true); Mat approxCurveM(approxCurve); Mat curve_lap; calc_laplacian(approxCurveM, curve_lap); //calc laplacian hcr_ctr = 0; for (int i=0; i<approxCurve.size(); i++) { double n = norm(((Point2d*)(curve_lap.data))[i]); if (n > 10.0) { //high curvature point circle(outC, approxCurve[i], 3, Scalar(50,155,255), 2); hcr_ctr++; } } hc_stack.at(hc_stack_ptr) = hcr_ctr; hc_stack_ptr = (hc_stack_ptr + 1) % hc_stack.size(); Scalar _avg = mean(Mat(hc_stack)); if (abs(_avg[0] - (double)hcr_ctr) > 5.0) { //a big change in curvature = hand fisted/opened? cout << "Hand click!" << endl; send_event("HandClick", ""); } if (mode_state == MODE_NONE) { } // imshow("out",out); //doHist(depthf,out); { //some debug on screen.. stringstream ss; ss << "high curve pts " << hcr_ctr << ", avg " << _avg[0]; putText(outC, ss.str(), Point(50,50), CV_FONT_HERSHEY_PLAIN, 2.0,Scalar(0,0,255), 2); } } else { //not registered, look for gestures if(appear.x<0) { //first appearence of blob appear = midBlob; // update_bg_model = false; appearTS = getTickCount(); cout << "appear ("<<appearTS<<") " << appear.x << "," << appear.y << endl; } else { //blob was seen before, how much time passed double timediff = ((double)getTickCount()-appearTS)/getTickFrequency(); if (timediff > .2 && timediff < 1.0) { //enough time passed from appearence line(outC, appear, Point(blb[0],blb[1]), Scalar(0,0,255), 3); if (appear.x - blb[0] > 100) { cout << "right"<<endl; appear.x = -1; send_event("SwipeRight", ""); update_bg_model = true; register_ctr = 0; } else if (appear.x - blb[0] < -100) { cout << "left" <<endl; appear.x = -1; send_event("SwipeLeft", ""); update_bg_model = true; register_ctr = 0; } else if (appear.y - blb[1] > 100) { cout << "up" << endl; appear.x = -1; send_event("SwipeUp", ""); update_bg_model = true; register_ctr = 0; } else if (appear.y - blb[1] < -100) { cout << "down" << endl; appear.x = -1; send_event("SwipeDown", ""); update_bg_model = true; register_ctr = 0; } } if(timediff >= 1.0) { cout << "a ghost..."<<endl; update_bg_model = true; //a second passed from appearence - reset 1st appear appear.x = -1; appearTS = -1; midBlob.x = midBlob.y = -1; } } } send_image(outC); } } else { send_image(depthf); register_ctr = MAX((register_ctr - 1),0); register_secondbloc_ctr = MAX((register_secondbloc_ctr - 1),0); } imshow("blob",outC); if (register_ctr <= 15 && registered) { midBlob.x = midBlob.y = -1; registered = false; mode_state = MODE_NONE; update_bg_model = true; cout << "unregister" << endl; send_event("Unregister", ""); } char k = cvWaitKey(5); if( k == 27 ) break; if( k == ' ' ) update_bg_model = !update_bg_model; if (k=='s') { cout << "send test event" << endl; send_event("TestEvent", ""); } } printf("-- done!\n"); pthread_join(ocv_thread, NULL); pthread_exit(NULL); return 0; }
void ImportTracker::get_update(S32 newid, BOOL justCreated, BOOL createSelected) { switch (state) { //lgg crap case WAND: if(justCreated && createSelected) { numberExpected--; if(numberExpected<=0) state=IDLE; LLMessageSystem* msg = gMessageSystem; msg->newMessageFast(_PREHASH_ObjectImage); msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->nextBlockFast(_PREHASH_ObjectData); msg->addU32Fast(_PREHASH_ObjectLocalID, (U32)newid); msg->addStringFast(_PREHASH_MediaURL, NULL); LLPrimitive obj; obj.setNumTEs(U8(10)); S32 shinnyLevel = 0; if(gSavedSettings.getString("EmeraldBuildPrefs_Shiny")== "None") shinnyLevel = 0; if(gSavedSettings.getString("EmeraldBuildPrefs_Shiny")== "Low") shinnyLevel = 1; if(gSavedSettings.getString("EmeraldBuildPrefs_Shiny")== "Medium") shinnyLevel = 2; if(gSavedSettings.getString("EmeraldBuildPrefs_Shiny")== "High") shinnyLevel = 3; for (int i = 0; i < 10; i++) { LLTextureEntry tex = LLTextureEntry(LLUUID(gSavedSettings.getString("EmeraldBuildPrefs_Texture"))); tex.setColor(gSavedSettings.getColor4("EmeraldBuildPrefs_Color")); tex.setAlpha(1.0 - ((gSavedSettings.getF32("EmeraldBuildPrefs_Alpha")) / 100.0)); tex.setGlow(gSavedSettings.getF32("EmeraldBuildPrefs_Glow")); if(gSavedSettings.getBOOL("EmeraldBuildPrefs_FullBright")) { tex.setFullbright(TEM_FULLBRIGHT_MASK); } tex.setShiny((U8) shinnyLevel & TEM_SHINY_MASK); obj.setTE(U8(i), tex); } obj.packTEMessage(gMessageSystem); msg->sendReliable(gAgent.getRegion()->getHost()); msg->newMessage("ObjectFlagUpdate"); msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() ); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->addU32Fast(_PREHASH_ObjectLocalID, (U32)newid ); msg->addBOOLFast(_PREHASH_UsePhysics, gSavedSettings.getBOOL("EmeraldBuildPrefs_Physical")); msg->addBOOL("IsTemporary", gSavedSettings.getBOOL("EmeraldBuildPrefs_Temporary")); msg->addBOOL("IsPhantom", gSavedSettings.getBOOL("EmeraldBuildPrefs_Phantom") ); msg->addBOOL("CastsShadows", true ); msg->sendReliable(gAgent.getRegion()->getHost()); if(gSavedSettings.getBOOL("EmeraldBuildPrefs_EmbedItem")) { LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem((LLUUID)gSavedSettings.getString("EmeraldBuildPrefs_Item")); LLViewerObject* objectp = find((U32)newid); if(objectp) if(item) { if(item->getType()==LLAssetType::AT_LSL_TEXT) { LLToolDragAndDrop::dropScript(objectp, item, TRUE, LLToolDragAndDrop::SOURCE_AGENT, gAgent.getID()); }else { LLToolDragAndDrop::dropInventory(objectp,item,LLToolDragAndDrop::SOURCE_AGENT,gAgent.getID()); } } } msg->newMessageFast(_PREHASH_ObjectPermissions); msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->nextBlockFast(_PREHASH_HeaderData); msg->addBOOLFast(_PREHASH_Override, FALSE); msg->nextBlockFast(_PREHASH_ObjectData); msg->addU32Fast(_PREHASH_ObjectLocalID, (U32)newid); msg->addU8Fast(_PREHASH_Field, PERM_NEXT_OWNER); msg->addBOOLFast(_PREHASH_Set, PERM_ITEM_UNRESTRICTED); U32 flags = 0; if ( gSavedSettings.getBOOL("NextOwnerCopy") ) { flags |= PERM_COPY; } if ( gSavedSettings.getBOOL("NextOwnerModify") ) { flags |= PERM_MODIFY; } if ( gSavedSettings.getBOOL("NextOwnerTransfer") ) { flags |= PERM_TRANSFER; } msg->addU32Fast(_PREHASH_Mask, flags); msg->sendReliable(gAgent.getRegion()->getHost()); //llinfos << "LGG SENDING CUBE TEXTURE.." << llendl; } break; case BUILDING: if (justCreated && (int)localids.size() < linkset.size()) { localids.push_back(newid); localids.sort(); localids.unique(); linkset[localids.size() -1]["LocalID"] = newid; LLSD prim = linkset[localids.size() -1]; //MAKERIGHT if (!(prim).has("Updated")) { ++updated; send_shape(prim); send_image(prim); send_extras(prim); send_namedesc(prim); send_vectors(prim,updated); send_properties(prim, updated); send_inventory(prim); (prim)["Updated"] = true; } if ((int)localids.size() < linkset.size()) { plywood_above_head(); return; } else { if (updated >= linkset.size()) { updated=0; llinfos << "FINISHED BUILDING, LINKING.." << llendl; state = LINKING; link(); } } } break; case LINKING: link(); break; } }
int GrabSend::loop(){ std::string status = "loop init"; double loopstart; while(!stop){ try{ loopstart = t_now = clock(); t_now = loopstart; // Grab an image from the camera status = "wait for image"; _TIME /* Get ladybugImage */ lady->grabImage(&image); _HANDLE_ERROR_LADY // Grab an image from the camera status = "got images"; _TIME prefill_sensordata(message, image); status = "get sensordata"; _TIME //send protobuff message pb_send(socket, &message, ZMQ_SNDMORE); status = "send header"; _TIME status = "extract images " + std::to_string(nr); int flag = ZMQ_SNDMORE; for( unsigned int uiCamera = 0; uiCamera < LADYBUG_NUM_CAMERAS; uiCamera++ ) { if( uiCamera == LADYBUG_NUM_CAMERAS-1 ){ flag = 0; } if(separatedColors) { unsigned int index = uiCamera*4; //send images //RGB expected at reciever // Red = Index + 3 send_image(index+red_offset, &image, socket, ZMQ_SNDMORE); // Green = Index + 1 || 2 send_image(index+green_offset, &image, socket, ZMQ_SNDMORE); // Blue = Index 0 send_image(index+blue_offset, &image, socket, flag); }else{ /* RGGB RAW */ send_image(uiCamera, &image, socket, flag); } } // end uiCamera loop _TIME //message.Clear(); ++nr; socket_watchdog->send(msg_watchdog, ZMQ_NOBLOCK); // Loop done if(lady->isFileStream()){ double sleepTime = lady->getCycleTime() - (clock() - loopstart) -1; if(sleepTime > 0){ Sleep(sleepTime); } } else{ Sleep(1); // Chance to terminate the thread } status = "Sum loop"; t_now = loopstart; _TIME } catch(std::exception e){ stop = true; } } return 0; _EXIT: return 1; }