void pigalePaint::DrawText(QPainter *p,Tpoint &a,tvertex v,int col,int center) // draw text centered at a, with a surrounding rectangle // center=1 center // center=0 horizontal {QString t = getVertexLabel(GCP,v); QPen pn = p->pen();pn.setWidth(1);pn.setColor(color[Black]);p->setPen(pn); QSize size = QFontMetrics(p->font()).size(Qt::AlignCenter,t); double nx = size.width() + 4; double ny = size.height(); if(t.length() == 0)nx = ny= 8; QRect rect; //if pn.setWidth() > 1 => rect increase if(center) rect = QRect((int)(to_x(a.x())-nx/2+.5),(int)(to_y(a.y())-ny/2+.5),(int)(nx+.5),(int)(ny+.5)); else rect = QRect((int)(to_x(a.x())-nx/2+.5),(int)(to_y(a.y())-ny+1.),(int)(nx+.5),(int)(ny+.5)); QBrush pb = p->brush(); pb.setStyle(Qt::SolidPattern); pb.setColor(color[bound(col,0,16)]); //pb.setColor(color[White]); p->setBrush(pb); //pn.setColor(color[col]);pn.setWidth(1);p->setPen(pn); pn.setWidth(1);pn.setColor(color[Black]);p->setPen(pn); p->drawRect(rect); if(ny < 6)return; p->drawText(rect,Qt::AlignCenter,t); }
void pigalePaint::DrawSeg(QPainter *p,Tpoint &a,Tpoint &b,int col,int width) {QPen pn = p->pen(); QPoint ps = QPoint(to_x(a.x()),to_y(a.y())); QPoint pt = QPoint(to_x(b.x()),to_y(b.y())); pn.setColor(color[bound(col,1,16)]); pn.setWidth(width); p->setPen(pn); p->drawLine(ps,pt); }
bool Maze::dir_in_bounds(int pos, int dir) { switch (dir) { case N : return (to_y(pos) > 0); case S : return (to_y(pos) < y_size-1); case W : return (to_x(pos) > 0); case E : return (to_x(pos) < x_size-1); default: return false; } }
void pigalePaint::DrawTriangle(QPainter *p,Tpoint &p1,Tpoint &p2,Tpoint &p3,int col) {QPen pn = p->pen();pn.setWidth(1);pn.setColor(color[Black]);p->setPen(pn); QBrush pb = p->brush();pb.setStyle(Qt::SolidPattern); pb.setColor(color[bound(col,1,16)]);p->setBrush(pb); QPoint vertices[3]; vertices[0] = QPoint((int)to_x(p1.x()),(int)to_y(p1.y())); vertices[1] = QPoint((int)to_x(p2.x()),(int)to_y(p2.y())); vertices[2] = QPoint((int)to_x(p3.x()),(int)to_y(p3.y())); p->drawConvexPolygon(vertices,3); }
void Maze::sdl_paint_all(SDLWindow *window, int path_width) { window->clear(); for(int pos = 0; pos < size; pos++) { temp_x0 = to_x(pos) * (path_width + 1); temp_y0 = to_y(pos) * (path_width + 1); temp_x1 = temp_x0 + path_width + 1; temp_y1 = temp_y0 + path_width + 1; if(walls[pos] == 0 && !actv[pos]) { window -> setColor(0xCC, 0xCC, 0xCC); window -> fillRect(temp_x0+1, temp_y0+1, path_width, path_width); } else { if (actv[pos]) { window -> setColor(0xDE, 0xCA, 0xFF); window -> fillRect(temp_x0, temp_y0, path_width+1, path_width+1); } window -> setColor(0x00, 0x00, 0x00); if ( !(walls[pos] & dirEnc[N]) ) window -> drawLine(temp_x0, temp_y0, temp_x1, temp_y0); if ( !(walls[pos] & dirEnc[S]) ) window -> drawLine(temp_x0, temp_y1, temp_x1, temp_y1); if ( !(walls[pos] & dirEnc[W]) ) window -> drawLine(temp_x0, temp_y0, temp_x0, temp_y1); if ( !(walls[pos] & dirEnc[E]) ) window -> drawLine(temp_x1, temp_y0, temp_x1, temp_y1); } } }
void Maze::sdl_paint_count(SDLWindow *window, float div) { if(window -> SCREEN_WIDTH < x_size || window -> SCREEN_HEIGHT < y_size) return; for (int i = 0; i < size; i++) { window -> setColorHSV(dist[i] / div, 0.5, 0.9); window -> setPixel(to_x(i), to_y(i)); } }
void pigalePaint::DrawRect(QPainter *p,Tpoint &a,double nx,double ny,int col) // draw a rectangle centered at a {QPen pn = p->pen();pn.setWidth(2);pn.setColor(color[Black]);p->setPen(pn); QBrush pb = p->brush();pb.setStyle(Qt::SolidPattern); pb.setColor(color[bound(col,1,16)]);p->setBrush(pb); // nx *= xscale; ny *= yscale; // p->drawRect(QRect(to_x(a.x()-nx/2+.5),to_y(a.y()-ny/2+.5),(int)(nx+.5),(int)(ny+.5))); p->drawRect(QRect((int)(to_x(a.x()) - nx*Min(xscale,yscale)/2), (int)(to_y(a.y())- ny*Min(xscale,yscale)/2), (int)(nx*Min(xscale,yscale)), (int)(ny*Min(xscale,yscale)))); }
void pigalePaint::wheelEvent(QWheelEvent *event) {//event->accept(); zoom = (event->delta() > 0) ? 1.1 : 1./1.1; double xx0 = ((double)posClick.x() - xtr)/xscale; double yy0 = -((double)posClick.y() + ytr - this->height())/yscale; xscale *= zoom ;yscale *= zoom; xtr += posClick.x() - to_x(xx0); ytr += to_y(yy0) - posClick.y(); repaint(geometry()); }
void pigalePaint::DrawText(QPainter *p,double x,double y,double nx,double ny,tvertex v,int col) // draw centered text in rectangle left at x,y of size: nx,ny {QPen pn = p->pen();pn.setColor(color[Black]); nx *= xscale; ny *= yscale; QRect rect = QRect(to_x(x),to_y(y),(int)(nx+.5),(int)(ny+.5)); QBrush pb = p->brush();pb.setStyle(Qt::SolidPattern); pb.setColor(color[bound(col,1,16)]);p->setBrush(pb); pn.setWidth(1);p->setPen(pn); p->drawRect(rect); pn.setWidth(1);p->setPen(pn); QString t = getVertexLabel(GCP,v); p->drawText(rect,Qt::AlignCenter,t); }
void pigalePaint::keyPressEvent(QKeyEvent *k) {int key = k->key(); if(key == Qt::Key_Up) zoom = 1.1; else if(key == Qt::Key_Down) zoom = 1/1.1; else if(key == Qt::Key_Home) {xtr = xtr0; ytr = ytr0; xscale = xscale0; yscale = yscale0; } else return; //k->accept(); if(key != Qt::Key_Home) {double xx0 = ((double)posClick.x() - xtr)/xscale; double yy0 = -((double)posClick.y() + ytr - this->height())/yscale; xscale *= zoom ;yscale *= zoom; xtr += posClick.x() - to_x(xx0); ytr += to_y(yy0) - posClick.y(); } repaint(geometry()); }
bool DataIOStanford::read_next_frame(cv::Mat& frame_rgb, cv::Mat& frame_depth) { // while (true) { if(!stanford_eval::read_frame()) { if (!stanford_eval::next_file()) return false; }; stanford_eval::Frame f = stanford_eval::frame; cv::Mat frame(cv::Size(f.C, f.R), CV_32F); for (int i = 0; i < f.N; ++i) { frame.at<float>(i % f.R, i/f.R) = -(f.points[i][2] + 2.0); } cv::normalize(frame, frame_depth, 0, 1.0, cv::NORM_MINMAX); for (int i = 0; i < f.N; ++i) { if (frame_depth.at<float>(i % f.R, i/f.R) > 0.7f) frame_depth.at<float>(i % f.R, i/f.R) = 0.0f; } // Ground truth if (f.markers[1].cond > 0) { centre_truth_head.x = to_x(f.markers[1].x); centre_truth_head.y = to_y(f.markers[1].y + 0.1); } else if (f.markers[3].cond > 0) { centre_truth_head.x = to_x(f.markers[3].x); centre_truth_head.y = to_y(f.markers[3].y + 0.1); } else { centre_truth_head.x = -1; } if (f.markers[24].cond > 0) { centre_truth_left_hand.x = to_x(f.markers[24].x); centre_truth_left_hand.y = to_y(f.markers[24].y); } else if (f.markers[28].cond > 0) { centre_truth_left_hand.x = to_x(f.markers[28].x); centre_truth_left_hand.y = to_y(f.markers[28].y); } else { centre_truth_left_hand.x = -1; } if (f.markers[16].cond > 0) { centre_truth_right_hand.x = to_x(f.markers[16].x); centre_truth_right_hand.y = to_y(f.markers[16].y); } else if (f.markers[19].cond > 0) { centre_truth_right_hand.x = to_x(f.markers[19].x); centre_truth_right_hand.y = to_y(f.markers[19].y); } else { centre_truth_right_hand.x = -1; } if (f.markers[35].cond > 0) { centre_truth_left_foot.x = to_x(f.markers[35].x); centre_truth_left_foot.y = to_y(f.markers[35].y - 0.2); } else if (f.markers[37].cond > 0) { centre_truth_left_foot.x = to_x(f.markers[37].x); centre_truth_left_foot.y = to_y(f.markers[37].y - 0.2); } else { centre_truth_left_foot.x = -1; } if (f.markers[43].cond > 0) { centre_truth_right_foot.x = to_x(f.markers[43].x); centre_truth_right_foot.y = to_y(f.markers[43].y - 0.2); } else if (f.markers[41].cond > 0) { centre_truth_right_foot.x = to_x(f.markers[41].x); centre_truth_right_foot.y = to_y(f.markers[41].y - 0.2); } else { centre_truth_right_foot.x = -1; } return true; }
void DataIOStanford::extract_parts() { /* initialize random seed: */ srand (time(NULL)); // Creating directory structure const std::string kTrainingDataPathHead = kPath + "/training"; boost::filesystem::path training_data_path_head(kTrainingDataPathHead); boost::filesystem::create_directory(training_data_path_head); std::ofstream data((kTrainingDataPathHead + "/data.txt").c_str()); if (!data.is_open()) { std::cerr << "Unable to create training data files!" << std::endl; } int head_idx, hand_idx, leg_idx; head_idx = hand_idx = leg_idx = 1; cv::Mat frame, frame_dummy; while (read_next_frame(frame_dummy, frame)) { //if(!) { stanford_eval::next_file(); }; stanford_eval::Frame f = stanford_eval::frame; // cv::Mat frame(cv::Size(f.C, f.R), CV_32F); // // for (int i = 0; i < f.N; ++i) { // frame.at<float>(i % f.R, i/f.R) = -(static_cast<float>(f.points[i][2]) + 2.f); // } // // cv::normalize(frame, frame, 0, 1.f, cv::NORM_MINMAX); std::vector<int> positive_centres; // Head if (f.markers[3].cond > 0 && f.markers[1].cond > 0) { extract_positive_part(frame, data, f.markers[3].x, f.markers[3].y + 0.1, f.markers[1].x, f.markers[1].y + 0.1, classifier::HEAD, true); extract_positive_part(frame, data, f.markers[3].x, f.markers[3].y + 0.1, f.markers[3].x, f.markers[1].y + 0.1, classifier::HEAD, true); positive_centres.push_back(to_x(f.markers[1].x)); positive_centres.push_back(to_y(f.markers[1].y + 0.1)); positive_centres.push_back(to_x(f.markers[3].x)); positive_centres.push_back(to_y(f.markers[3].y + 0.1)); } // Left hand if (f.markers[28].cond > 0 && f.markers[24].cond > 0) { extract_positive_part(frame, data, f.markers[28].x, f.markers[28].y, f.markers[24].x, f.markers[24].y, classifier::LEFT_HAND, true); positive_centres.push_back(to_x(f.markers[24].x)); positive_centres.push_back(to_y(f.markers[24].y)); } // Right hand if (f.markers[19].cond > 0 && f.markers[16].cond > 0) { extract_positive_part(frame, data, f.markers[19].x, f.markers[19].y, f.markers[16].x, f.markers[16].y, classifier::RIGHT_HAND, true); positive_centres.push_back(to_x(f.markers[16].x)); positive_centres.push_back(to_y(f.markers[16].y)); } // Left foot if (f.markers[35].cond > 0 && f.markers[37].cond > 0) { extract_positive_part(frame, data, f.markers[37].x, f.markers[37].y - 0.2, f.markers[35].x, f.markers[35].y - 0.2, classifier::LEFT_FOOT, true); positive_centres.push_back(to_x(f.markers[35].x)); positive_centres.push_back(to_y(f.markers[35].y - 0.2)); } // Right foot if (f.markers[43].cond > 0 && f.markers[41].cond > 0) { extract_positive_part(frame, data, f.markers[41].x, f.markers[41].y - 0.2, f.markers[43].x, f.markers[43].y - 0.2, classifier::RIGHT_FOOT, true); positive_centres.push_back(to_x(f.markers[43].x)); positive_centres.push_back(to_y(f.markers[43].y - 0.2)); } for (int j = 0; j < 12; j++) { extract_negative_part(frame, data, positive_centres); } } }
void pigalePaint::DrawText(QPainter *p,double x,double y,QString txt) {QPen pn = p->pen();pn.setWidth(1);pn.setColor(color[Black]);p->setPen(pn); p->drawText(to_x(x),to_y(y),txt); }