Example #1
0
void PenCommandObject::release()
{
  auto segts_tpl = filterSegments();
  // First handle the case of a single point
  if (m_segment.points().size() == 1)
  {
    cancel();
  }
  else
  {
    release_n(std::move(segts_tpl));
  }
}
Example #2
0
void PenCommandObject::move()
{
  // getSegmentId *has* to be prior to filterSegments for middleBegin /
  // middleEnd
  auto point_array_id = getSegmentId(m_startSegments);
  auto segts_tpl = filterSegments();
  auto& middleBegin = std::get<0>(segts_tpl);
  auto& middleEnd = std::get<1>(segts_tpl);
  auto& segts = std::get<2>(segts_tpl);

  auto dat_base = m_segment.toSegmentData();
  dat_base.id = point_array_id;
  dat_base.start = m_minPress;
  dat_base.end = m_maxPress;

  segts.reserve(segts.size() + 3);

  optional<std::size_t> middle_begin_p{};
  optional<std::size_t> middle_end_p{};
  if (middleBegin)
  {
    segts.push_back(*std::move(middleBegin));
    middle_begin_p = segts.size() - 1;
  }
  if (middleEnd)
  {
    segts.push_back(*std::move(middleEnd));
    middle_end_p = segts.size() - 1;
  }

  segts.push_back(dat_base);
  SegmentData& dat = segts.back();

  if (middle_begin_p && middle_end_p
      && segts[*middle_begin_p].id == segts[*middle_end_p].id)
  {
    segts[*middle_end_p].id = getSegmentId(segts);
    for (auto& seg : segts)
    {
      if (seg.id == segts[*middle_end_p].following)
      {
        seg.previous = segts[*middle_end_p].id;
        break;
      }
    }
  }

  if (middle_begin_p)
  {
    SegmentData& seg = segts[*middle_begin_p];
    seg.end = m_minPress;
    seg.following = dat.id;
    dat.previous = seg.id;
  }

  if (middle_end_p)
  {
    SegmentData& seg = segts[*middle_end_p];
    seg.start = m_maxPress;
    seg.previous = dat.id;
    dat.following = seg.id;
  }

  submit(std::move(segts));
}
Example #3
0
int main( int argc, char** argv){
	
	/*colors*/
	CvScalar green = CV_RGB(0,255,0);
	CvScalar white = CV_RGB(255,255,255);
	CvScalar black = CV_RGB(0,0,0);
	CvScalar red = CV_RGB(255,0,0);
	CvScalar blue = CV_RGB(0,0,255);


	cvNamedWindow( "opencv on acid",CV_WINDOW_AUTOSIZE);
	cvNamedWindow( "lsd",CV_WINDOW_AUTOSIZE);
	
	CvCapture* capture;
	
	if ( argc == 1 ) {
	 	capture = cvCreateCameraCapture (0);
	} else {
	 	capture = cvCreateFileCapture (argv[1]);
	}
	assert( capture != NULL );
	
	IplImage* frame;
	image_double image;
	int width, height, i, j;
	
	while (1) {
		frame = cvQueryFrame( capture );
		if( !frame ) break;

		/* get image properties */
		width  = frame->width;
		height = frame->height;

		/* create new image for the grayscale version */
		IplImage* frameBW = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 1 );

		/*convert to grayscale*/ 
		cvCvtColor( frame , frameBW, CV_RGB2GRAY);
		
		/*cast into lsd image struct*/
		image = new_image_double(width, height);
		uchar* data = (uchar*)frameBW->imageData;
		for (i=0;i<height;i++){
			for(j=0;j<width;j++){
				image->data[ j + i * width ] = data[j + i*width];
			};
		};
		
		/*run lsd*/
		ntuple_list ntl;
		ntl = lsd(image);
		free_image_double(image);
		
		/*filter lsd segments*/		
		int degrees_thr = 20;	// degrees of threshold
		int distance_thr = 49;	// 7 pixels
		ntuple_list ntlFilt = new_ntuple_list(5);
		filterSegments( ntl, ntlFilt , distance_thr);
		/********************/
		
		//printf("A ver: %3.2f\n",ntl->values[1]);
		
		/*draw segments on frame and frameLsd*/
		IplImage* frameLsd = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 3 );
		cvSet(frameLsd, black, 0);
		for (j=0; j<ntl->size ; j++){		
			//define segment end-points
			CvPoint pt1 = cvPoint(ntl->values[ 0 + j * ntl->dim ],ntl->values[ 1 + j * ntl->dim ]);
			CvPoint pt2 = cvPoint(ntl->values[ 2 + j * ntl->dim ],ntl->values[ 3 + j * ntl->dim ]);
	
			// draw line on frame
			cvLine(frame,pt1,pt2,white,1.5,8,0);
			
			// draw line on frameLsd
			cvLine(frameLsd,pt1,pt2,white,1.5,8,0);
		}
		
		
		/*draw segments on actual frameLsdFilt*/
		IplImage* frameLsdFilt = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 3 );
		cvSet(frameLsdFilt, black, 0);	
		j = 0;
		for (j=0; j<ntlFilt->size ; j++){		
			//define segment end-points
			CvPoint pt1 = cvPoint(ntlFilt->values[ 0 + j * ntlFilt->dim ],ntlFilt->values[ 1 + j * ntlFilt->dim ]);
			CvPoint pt2 = cvPoint(ntlFilt->values[ 2 + j * ntlFilt->dim ],ntlFilt->values[ 3 + j * ntlFilt->dim ]);
			
			// draw line on frameLsd
			cvLine(frameLsdFilt,pt1,pt2,white,1.5,8,0);
		}		
					
		
		cvShowImage("opencv on acid",frame);
		cvShowImage("lsd",frameLsd);
		cvShowImage("lsd filtrado",frameLsdFilt);
		char c = cvWaitKey(25);
		if( c == 27 ) break;
	}
	cvReleaseCapture( &capture );
	cvDestroyWindow( "opencv on acid");
	cvDestroyWindow( "lsd");
	cvDestroyWindow( "lsd filtrado");
}