void testApp::updateTrianglesRandom() { Mat mat = Mat(kinect.getHeight(), kinect.getWidth(), CV_32FC1, kinect.getDistancePixels()); Sobel(mat, sobelxy, CV_32F, 1, 1); sobelxy = abs(sobelxy); int randomBlur = panel.getValueI("randomBlur") * 2 + 1; boxFilter(sobelxy, sobelbox, 0, cv::Size(randomBlur, randomBlur), Point2d(-1, -1), false); triangulator.reset(); points.clear(); int i = 0; attempts = 0; int randomCount = panel.getValueI("randomCount"); float randomWeight = panel.getValueF("randomWeight"); while(i < randomCount) { Point2d curPosition(1 + (int) ofRandom(sobelbox.cols - 3), 1 + (int) ofRandom(sobelbox.rows - 3)); float curSample = sobelbox.at<unsigned char>(curPosition) / 255.f; float curGauntlet = powf(ofRandom(0, 1), 2 * randomWeight); if(curSample > curGauntlet) { points.push_back(toOf(curPosition)); triangulator.addPoint(curPosition.x, curPosition.y, 0); sobelbox.at<unsigned char>(curPosition) = 0; // don't do the same point twice i++; } attempts++; if(i > attempts * 100) { break; } } // add the edges int w = mat.cols; int h = mat.rows; for(int x = 0; x < w; x++) { triangulator.addPoint(x, 0, 0); triangulator.addPoint(x, h - 1, 0); } for(int y = 0; y < h; y++) { triangulator.addPoint(0, y, 0); triangulator.addPoint(w - 1, y, 0); } triangulator.triangulate(); int n = triangulator.triangles.size(); triangles.resize(n); for(int i = 0; i < n; i++) { triangles[i].vert3 = triangulator.triangles[i].points[0]; triangles[i].vert2 = triangulator.triangles[i].points[1]; triangles[i].vert1 = triangulator.triangles[i].points[2]; } }
/** Internal do not use * \param[in] off * \param[in] way */ bool SdStreamBase::seekoff(off_type off, seekdir way) { pos_type pos; switch (way) { case beg: pos = off; break; case cur: pos = curPosition() + off; break; case end: pos = fileSize() + off; break; default: return false; } return seekpos(pos); }
void testApp::update() { Mat mat = getMat(depthImage); Sobel(mat, sobelxy, CV_32F, 1, 1); sobelxy = abs(sobelxy); boxFilter(sobelxy, sobelbox, 0, cv::Size(7, 7)); triangulator.init(); points.clear(); int i = 0; attempts = 0; while(i < 5000) { Point2d curPosition((int) ofRandom(sobelbox.cols - 1), (int) ofRandom(sobelbox.rows - 1)); float curSample = sobelbox.at<unsigned char>(curPosition) / 255.f; float curGauntlet = powf(ofRandom(0, 1), 2 * (float) mouseX / ofGetWidth()); if(curSample > curGauntlet) { points.push_back(makeVec(curPosition)); triangulator.addPoint(curPosition.x, curPosition.y); sobelbox.at<unsigned char>(curPosition) = 0; // don't do the same point twice i++; } attempts++; if(i > attempts * 100) { break; } } int w = mat.cols - 1; int h = mat.rows - 1; triangulator.addPoint(0, 0); triangulator.addPoint(w, 0); triangulator.addPoint(w, h); triangulator.addPoint(0, h); triangulator.triangulate(); }