void testApp::draw() { ofBackground(0); depthImage.draw(0, 0); ofEnableBlendMode(OF_BLENDMODE_ADD); drawMat(sobelxy, 0, 0); ofDisableBlendMode(); drawMat(sobelbox, 640, 0); triangulator.drawLines(); ofDrawBitmapString(ofToString(attempts), 10, 20); }
void LukasKanadeOpticalFlow::drawMotionField_GPU(cv::gpu::GpuMat &imgU, cv::gpu::GpuMat &imgV, cv::gpu::GpuMat &imgMotion, int xSpace, int ySpace, float minCutoff, float maxCutoff, float multiplier, CvScalar color) { cv::Mat uMat( imgU ); cv::Mat vMat( imgV ); cv::Mat drawMat(cv::Size( imgU.size().width, imgU.size().height), CV_8UC3 ); int x = 0, y = 0; float *ptri; float deltaX = 0.0, deltaY = 0.0, angle = 0.0, hyp = 0.0; cv::Point p0, p1; for( y = ySpace; y < uMat.rows; y += ySpace ) { for(x = xSpace; x < uMat.cols; x += xSpace ) { p0.x = x; p0.y = y; ptri = uMat.ptr<float>(y); deltaX = ptri[x]; ptri = vMat.ptr<float>(y); deltaY = ptri[x]; angle = atan2(deltaY, deltaX); hyp = sqrt(deltaX*deltaX + deltaY*deltaY); if( hyp > minCutoff && hyp < maxCutoff ) { p1.x = p0.x + cvRound(multiplier*hyp*cos(angle)); p1.y = p0.y + cvRound(multiplier*hyp*sin(angle)); cv::line(drawMat,p0,p1,color,1,CV_AA,0); /* p0.x = p1.x + cvRound(2*cos(angle-M_PI + M_PI/4)); p0.y = p1.y + cvRound(2*sin(angle-M_PI + M_PI/4)); cv::line( imgMotion, p0, p1, color,1, CV_AA, 0); p0.x = p1.x + cvRound(2*cos(angle-M_PI - M_PI/4)); p0.y = p1.y + cvRound(2*sin(angle-M_PI - M_PI/4)); cv::line( imgMotion, p0, p1, color,1, CV_AA, 0); */ } } } imgMotion.upload( drawMat ); }
void LukasKanadeOpticalFlow::apply( cv::gpu::GpuMat * _gpu_frame ) { // create new local copy cv::gpu::GpuMat newMat; // convert to 8bit greyscale cv::gpu::cvtColor( *_gpu_frame, newMat, CV_BGRA2GRAY ); if( newMat.size() != last_gpu_frame.size() ) { // if the roi was resized, resie the last_gpu_frame, too last_gpu_frame = cv::gpu::GpuMat( newMat.rows, newMat.cols, CV_8UC1 ); } if( last_gpu_frame.type() == newMat.type() ) { // do the flow calculation dflow_lukaskanade.dense( last_gpu_frame, newMat, uGPU, vGPU ); } // copy the current frame to the last frame, necessary for computing the next flow newMat.copyTo( last_gpu_frame ); cv::Mat uMat( uGPU ); cv::Mat vMat( vGPU ); std::cout << "neMat type:" << newMat.type() << std::endl; cv::gpu::cvtColor( newMat, newMat, CV_GRAY2BGR ); cv::Mat drawMat( newMat.rows, newMat.cols, newMat.type() ); //drawMotionField_GPU( uGPU, vGPU, newMat, 10, 10, 0.0, 40.0, 1.0, CV_RGB( 230, 230, 230 ) ); drawColorField( uMat, vMat, drawMat ); //drawMotionField( uMat, vMat, drawMat, 10, 10, 20, 100, 1.0, cv::Scalar( 255, 0, 0 ) ); cv::cvtColor( drawMat, drawMat, CV_BGR2RGBA ); _gpu_frame->upload( drawMat ); //newMat.copyTo( *_gpu_frame ); }
void drawMat(Mat& mat, float x, float y) { drawMat(mat, x, y, mat.cols, mat.rows); }