Пример #1
0
void LevelCorrection::RebuildOutputDlg()
{
	//clear
	cvSet(m_output_sld_img, cvScalar(255,255,255));

	int npts = 3; 
	CvPoint** pts = (CvPoint**) cvAlloc(sizeof(CvPoint*) * 1);
	pts[0] = (CvPoint*) cvAlloc(sizeof(CvPoint) * 3);

	//min slider
	pts[0][0].x = m_min_out_val - LC_SLD_RAD;
	pts[0][0].y = LC_OUTPUT_SLD_H-1;
	pts[0][1].x = m_min_out_val;
	pts[0][1].y = 0;
	pts[0][2].x = m_min_out_val + LC_SLD_RAD;
	pts[0][2].y = LC_OUTPUT_SLD_H-1;
	cvFillPoly(m_output_sld_img, pts, &npts, 1, LC_OUTPUT_MIN_SLD_COLOR, CV_AA, 0);
	cvPolyLine(m_output_sld_img, pts, &npts, 1, 1, CV_RGB(0,0,0), 1, CV_AA, 0);

	//max slider
	pts[0][0].x = m_max_out_val - LC_SLD_RAD;
	pts[0][1].x = m_max_out_val;
	pts[0][2].x = m_max_out_val + LC_SLD_RAD;
	cvFillPoly(m_output_sld_img, pts, &npts, 1, LC_OUTPUT_MAX_SLD_COLOR, CV_AA, 0);
	cvPolyLine(m_output_sld_img, pts, &npts, 1, 1, CV_RGB(0,0,0), 1, CV_AA, 0);

	cvFree(&(pts[0]));
	cvFree(&pts);
}
Пример #2
0
void  cvPolyLineAA( CvArr* img, CvPoint** pts, int* npts, int contours,
                    int is_closed, double color, int scale )
{
    cvPolyLine( img, pts, npts, contours, is_closed,
                cvColorToScalar(color, cvGetElemType(img)),
                1, CV_AA, scale );
}
Пример #3
0
// 画多边形函数
void draw_polygon(IplImage * img)
{
	CvScalar value = getRandColor();
	if(iNumofPoints == 0)
		return;

	// 遍历链表,取出point
	myPoints* p;
	int count = 0;
	
	printf("%d\t", iNumofPoints);
	g_polygon_pts[0] = (CvPoint*)malloc( sizeof(CvPoint) * iNumofPoints );
	for(p = pHead; p != NULL; p = p->next, count++)
	{
		g_polygon_pts[0][count] = p->point;
		printf("(%d, %d)  ",  p->point.x, p->point.y);
	}
	printf("\n");
	if(g_polygon_npts == NULL)
	{
		g_polygon_npts = (int*)malloc(sizeof(int));
	}
	g_polygon_npts[0] = iNumofPoints;
	cvPolyLine( img, g_polygon_pts, g_polygon_npts, 1, 0, value, 2 );
}
Пример #4
0
void drawSquares(IplImage* img, CvSeq* squares, PointMatrix &mat)
{
        CvSeqReader reader;
        IplImage* cpy = cvCloneImage(img);

        cvStartReadSeq(squares, &reader, 0);

        for (int i = 0; i < squares->total; i++) {
                CvPoint pt[4], *rect = pt;
                int count = 4;
                CV_READ_SEQ_ELEM(pt[0], reader);
                CV_READ_SEQ_ELEM(pt[1], reader);
                CV_READ_SEQ_ELEM(pt[2], reader);
                CV_READ_SEQ_ELEM(pt[3], reader);

                cvLine(cpy, pt[0], pt[2], CV_RGB(0, 0, 0), 1);
                cvLine(cpy, pt[1], pt[3], CV_RGB(255, 255, 0), 1);

                MyCvPoint myCvPoint( (pt[0].x + pt[2].x) /2, (pt[1].y + pt[2].y)/2, img->width, img->height);

                mat.AddMem(myCvPoint);

                cvPolyLine(cpy, &rect, &count, 1, 1, CV_RGB(0, 255, 255), 1, 8, 0);
        }
       // cvShowImage("After Modify", cpy);
        cvReleaseImage(&cpy);
}
Пример #5
0
/** Draws the identified Tetris pieces on the given image.
 */
void Camera::drawTetris( IplImage* img, CvSeq* tetrisPieces )
{
    CvSeqReader reader;
    int i;

    // initialize reader of the sequence
    cvStartReadSeq( tetrisPieces, &reader, 0 );

    // read the pieces sequence elements at a time (all vertices of the piece)
    for( i = 0; i < tetrisPieces->total; i += 6 )
    {
        CvPoint pt[6], *rect = pt;
        int count = 6;

        // read 6 vertices
        CV_READ_SEQ_ELEM( pt[0], reader );
        CV_READ_SEQ_ELEM( pt[1], reader );
        CV_READ_SEQ_ELEM( pt[2], reader );
        CV_READ_SEQ_ELEM( pt[3], reader );
        CV_READ_SEQ_ELEM( pt[4], reader );
        CV_READ_SEQ_ELEM( pt[5], reader );


        // draw the piece as a closed polyline
        cvPolyLine( img, &rect, &count, 1, 1, CV_RGB(255,0,0), 3, CV_AA, 0 );
    }

	return;
}
Пример #6
0
void EyeTracker::drawSquares(CvSeq* squares)
{
	CvSeqReader reader;
	int i;

	// initialize reader of the sequence
	cvStartReadSeq(squares, &reader, 0);
	CvPoint pt[4];
	CvPoint* rect;

	// read 4 sequence elements at a time (all vertices of a square)
	for(i = 0; i < squares->total; i += 4)
	{
		rect = pt;
		int count = 4;

		// read 4 vertices
		CV_READ_SEQ_ELEM(pt[0], reader);
		CV_READ_SEQ_ELEM(pt[1], reader);
		CV_READ_SEQ_ELEM(pt[2], reader);
		CV_READ_SEQ_ELEM(pt[3], reader);

		cvPolyLine(graySceneImagePts, &rect, &count, 1, 1, CV_RGB(255, 255, 255), 3, CV_AA, 0);
	}

	CvFont font;
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC, 1.0, 1.0, 0, 1);

	char s[20];
	sprintf(s, "Threshold = %d", squareThreshold);

	cvPutText(graySceneImagePts, s, cvPoint(30, 30), &font, cvScalar(255, 255, 0));
}
// the function draws all the squares in the image 
void drawSquares( IplImage* img, CvSeq* squares ) {  
	CvSeqReader reader; 
	IplImage* cpy = cvCloneImage( img );
	int i;  
	// initialize reader of the sequence 
	cvStartReadSeq( squares, &reader, 0 );
	// read 4 sequence elements at a time (all vertices of a square)  
	for( i = 0; i < squares->total; i += 4 ){  
		CvPoint* rect = pt;
		int count = 4; 
		// read 4 vertices  
		memcpy( pt, reader.ptr, squares->elem_size );
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader ); 
		memcpy( pt + 1, reader.ptr, squares->elem_size );  
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader );
		memcpy( pt + 2, reader.ptr, squares->elem_size );
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader );  
		memcpy( pt + 3, reader.ptr, squares->elem_size ); 
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader ); 
		// draw the square as a closed polyline 
		cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 3, CV_AA, 0 );
		if(i == 0){
			sort_vertex(rect);    //get the four vertex and sort them
			break;
		}
	}  
	// show the resultant image  
	cvShowImage( wndname, cpy );
	cvReleaseImage( &cpy ); 
} 
Пример #8
0
// the function draws all the squares in the image
void drawSquares( IplImage* img, CvSeq* squares )
{
    CvSeqReader reader;
    IplImage* cpy = cvCloneImage( img );
    int i;

    // initialize reader of the sequence
    cvStartReadSeq( squares, &reader, 0 );

    // read 4 sequence elements at a time (all vertices of a square)
    for( i = 0; i < squares->total; i += 4 )
    {
        CvPoint pt[4], *rect = pt;
        int count = 4;

        // read 4 vertices
        CV_READ_SEQ_ELEM( pt[0], reader );
        CV_READ_SEQ_ELEM( pt[1], reader );
        CV_READ_SEQ_ELEM( pt[2], reader );
        CV_READ_SEQ_ELEM( pt[3], reader );

        // draw the square as a closed polyline
        cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 3, CV_AA, 0 );
    }

    // show the resultant image
    cvShowImage( wndname, cpy );
    cvReleaseImage( &cpy );
}
Пример #9
0
void draw_subdiv_facet( IplImage* img, CvSubdiv2DEdge edge )
{
    CvSubdiv2DEdge t = edge;
    int i, count = 0;
    CvPoint* buf = 0;

    // count number of edges in facet
    do
    {
        count++;
        t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
    } while (t != edge );

    buf = (CvPoint*)malloc( count * sizeof(buf[0]));

    // gather points
    t = edge;
    for( i = 0; i < count; i++ )
    {
        CvSubdiv2DPoint* pt = cvSubdiv2DEdgeOrg( t );
        if( !pt ) break;
        buf[i] = cvPoint( cvRound(pt->pt.x), cvRound(pt->pt.y));
        t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
    }

    if( i == count )
    {
        CvSubdiv2DPoint* pt = cvSubdiv2DEdgeDst( cvSubdiv2DRotateEdge( edge, 1 ));
        cvFillConvexPoly( img, buf, count, CV_RGB(rand()&255,rand()&255,rand()&255), CV_AA, 0 );
        cvPolyLine( img, &buf, &count, 1, 1, CV_RGB(0,0,0), 1, CV_AA, 0);
        draw_subdiv_point( img, pt->pt, CV_RGB(0,0,0));
    }
    free( buf );
}
Пример #10
0
// the function draws all the squares in the image
void drawSquares(IplImage* imgSrc, CvSeq* squares)
{
	CvSeqReader reader;
	IplImage* imgCopy = cvCloneImage(imgSrc);
	int i;

	// initialize reader of the sequence
	cvStartReadSeq(squares, &reader, 0);

	// read 4 sequence elements at a time (all vertices of a square)
	printf("Found %d rectangles in image\n", squares->total / 4);

	for (i = 0; i < squares->total; i += 4)
	{
		CvPoint* pntRect = gPnt;
		int pntCount = 4;
		CvSeq* seqRect = cvCreateSeq(CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), gStorage);

		// read 4 vertices
		memcpy(gPnt, reader.ptr, squares->elem_size);
		CV_NEXT_SEQ_ELEM(squares->elem_size, reader);
		cvSeqPush(seqRect, &pntRect[0]);

		memcpy(gPnt + 1, reader.ptr, squares->elem_size);
		CV_NEXT_SEQ_ELEM(squares->elem_size, reader);
		cvSeqPush(seqRect, &pntRect[1]);

		memcpy(gPnt + 2, reader.ptr, squares->elem_size);
		CV_NEXT_SEQ_ELEM(squares->elem_size, reader);
		cvSeqPush(seqRect, &pntRect[2]);

		memcpy(gPnt + 3, reader.ptr, squares->elem_size);
		CV_NEXT_SEQ_ELEM(squares->elem_size, reader);
		cvSeqPush(seqRect, &pntRect[3]);

		// draw the square as a closed polyline
		cvPolyLine(imgCopy, &pntRect, &pntCount, 1, 1, CV_RGB(0, 255, 0), 1, CV_AA, 0);

		// draw the min outter rect
		CvBox2D box = cvMinAreaRect2(seqRect, NULL);
	    CvPoint2D32f ptBox[4];
	    cvBoxPoints(box, ptBox);
	    for(int i = 0; i < 4; ++i) {
	        cvLine(imgCopy, cvPointFrom32f(ptBox[i]), cvPointFrom32f(ptBox[((i+1)%4)?(i+1):0]), CV_RGB(255,0,0));
	    }

	}

	// show the resultant image
	cvShowImage(wndname, imgCopy);
	cvReleaseImage(&imgCopy);
}
int main (void)
{
    const char *image_name = "../data/test-image.jpg";

    IplImage *img = cvLoadImage(image_name, CV_LOAD_IMAGE_COLOR);
    if(img == NULL) {
        printf("Error: Cannot open %s\n", image_name);
        return -1;
    }
    // sanity checks (AsmSearchDll assumes imageData is vector of b,r,g bytes)

    if(img->nChannels != 3 || img->depth != IPL_DEPTH_8U ||
            img->origin != 0 || img->widthStep != 3 * img->width) {
        printf("Error: %s is an unrecognized image type\n", image_name);
        return -1;
    }

    // locate the facial landmarks with stasm

    int nlandmarks;
    int landmarks[500]; // space for x,y coords of up to 250 landmarks
    AsmSearchDll(&nlandmarks, landmarks,
                 image_name, img->imageData, img->width, img->height,
                 1 /* is_color */, NULL /* conf_file0 */, NULL /* conf_file1 */);
    if (nlandmarks == 0) {
        printf("\nError: Cannot locate landmarks in %s\n", image_name);
        return -1;
    }

#if 0 // print the landmarks if you want
    printf("landmarks:\n");
    for (int i = 0; i < nlandmarks; i++)
        printf("%3d: %4d %4d\n", i, landmarks[2 * i], landmarks[2 * i + 1]);
#endif

    // draw the landmarks on the image

    assert(sizeof(int) == 4); // needed for CvPoint typecast below
    int *p = landmarks;
    cvPolyLine(img, (CvPoint **)&p, &nlandmarks, 1, 1, CV_RGB(255,0,0));

    // show the image with the landmarks

    cvShowImage("stasm example", img);
    cvWaitKey(0);
    cvDestroyWindow("stasm example");
    cvReleaseImage(&img);

    return 0;
}
// the function draws all the squares in the image  
void drawSquares( IplImage* img, CvSeq* squares,CvPoint& centre)  
{  
	CvSeqReader reader;  
	IplImage* cpy = cvCloneImage( img );  
	int i;  
	static	int c=0;
	// initialize reader of the sequence  
	cvStartReadSeq( squares, &reader, 0 );  
	//	cout<<fabs(cvContourArea(squares,CV_WHOLE_SEQ)) <<endl;
	// read 4 sequence elements at a time (all vertices of a square)  
	for( i = 0; i < squares->total; i += 4 )  
	{  
		centre=cvPoint(0,0);
		CvPoint* rect = pt;  
		int count = 4;  

		// read 4 vertices  
		memcpy( pt, reader.ptr, squares->elem_size );  
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader );  
		memcpy( pt + 1, reader.ptr, squares->elem_size );  
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader );  
		memcpy( pt + 2, reader.ptr, squares->elem_size );  
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader );  
		memcpy( pt + 3, reader.ptr, squares->elem_size );  
		CV_NEXT_SEQ_ELEM( squares->elem_size, reader );  


		/*定形状*/
		if(isNotLicense(pt,count)) continue;
		// draw the square as a closed polyline   
		cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 3, CV_AA, 0 );  
		for(int j=0;j<count;j++){
			centre.x+=rect[j].x;
			centre.y+=rect[j].y;
		}
		centre.x/=4;
		centre.y/=4;
		cvCircle( cpy, centre,2, CV_RGB(255,0,255), 3, CV_AA, 0 );  
		c++;
		break;
	}
	//cout<<"count: "<<c<<endl;

	// show the resultant image  
	cvNamedWindow( wndname, 0 );  
//	cvShowImage( wndname, cpy );  
	cvReleaseImage( &cpy );  
	cvClearSeq(squares);

}  
Пример #13
0
void LevelCorrection::RebuildLevelDlg()
{
	//clear
	cvSet(m_level_sld_img, cvScalar(255,255,255));

	int npts = 3; 
	CvPoint** pts = (CvPoint**) cvAlloc(sizeof(CvPoint*) * 1);
	pts[0] = (CvPoint*) cvAlloc(sizeof(CvPoint) * 3);

	//min slider
	pts[0][0].x = m_min_level - LC_SLD_RAD;
	pts[0][0].y = LC_LEVEL_SLD_H-1;
	pts[0][1].x = m_min_level;
	pts[0][1].y = 0;
	pts[0][2].x = m_min_level + LC_SLD_RAD;
	pts[0][2].y = LC_LEVEL_SLD_H-1;
	cvFillPoly(m_level_sld_img, pts, &npts, 1, LC_LEVEL_MIN_SLD_COLOR, 8, 0);
	cvPolyLine(m_level_sld_img, pts, &npts, 1, 1, CV_RGB(0,0,0), 1, 8, 0);

	//max slider
	pts[0][0].x = m_max_level - LC_SLD_RAD;
	pts[0][1].x = m_max_level;
	pts[0][2].x = m_max_level + LC_SLD_RAD;
	cvFillPoly(m_level_sld_img, pts, &npts, 1, LC_LEVEL_MAX_SLD_COLOR, 8, 0);
	cvPolyLine(m_level_sld_img, pts, &npts, 1, 1, CV_RGB(0,0,0), 1, 8, 0);

	//
	int gamma_x = m_gamma*(m_max_level - m_min_level) + m_min_level + 0.5;
	pts[0][0].x = gamma_x - LC_SLD_RAD;
	pts[0][1].x = gamma_x;
	pts[0][2].x = gamma_x + LC_SLD_RAD;
	cvFillPoly(m_level_sld_img, pts, &npts, 1, LC_LEVEL_GAM_SLD_COLOR, 8, 0);
	cvPolyLine(m_level_sld_img, pts, &npts, 1, 1, CV_RGB(0,0,0), 1, 8, 0);

	cvFree(&(pts[0]));
	cvFree(&pts);
}
Пример #14
0
void RectDetector::DrawShape(IplImage* dst,const std::vector<RectShape>& shapes)
{
		// read 4 sequence elements at a time (all vertices of a square)
	for(int i = 0; i < shapes.size(); ++i )
	{
		CvPoint pt[4], *RectShape = pt;
		int count = 4;

		pt[0] = shapes[i].ltPoint;
		pt[1] = shapes[i].lbPoint;
		pt[2] = shapes[i].rbPoint;
		pt[3] = shapes[i].rtPoint;

		// draw the square as a closed polyline
		cvPolyLine( dst, &RectShape, &count, 1, 1, CV_RGB(0,255,0), 2, CV_AA, 0 );
	}

}
void CSquareDetection::DrawSquares( IplImage* img, CvSeq* squares, int* flag, CvScalar* color)
{
	int i;
	// read 4 sequence elements at a time (all vertices of a square)
	for( i = 0; i < squares->total; i += 4 )
	{
		if (flag[i/4] > -1)
		{
			CvPoint pt[4], *rect = pt;
			int count = 4;

			// read 4 vertices
			pt[0] = *((CvPoint*)cvGetSeqElem(squares, i));
			pt[1] = *((CvPoint*)cvGetSeqElem(squares, i+1));
			pt[2] = *((CvPoint*)cvGetSeqElem(squares, i+2));
			pt[3] = *((CvPoint*)cvGetSeqElem(squares, i+3));

			// draw the square as a closed polyline 
			cvPolyLine( img, &rect, &count, 1, 1, color[flag[i/4]], 1, CV_AA, 0 );
		}
	}
}
Пример #16
0
void drawPolyLine( ipl_image_wrapper& ipl_image
                   , const curve_vec_t& curves
                   , bool               is_closed
                   , PIXEL              color
                   , std::size_t        line_width )
{
    const std::size_t num_curves = curves.size();

    boost::scoped_array<int> num_points_per_curve( new int[num_curves] );

    std::size_t total_num_points = 0;
    for( std::size_t i = 0; i < num_curves; ++i )
    {
        num_points_per_curve[i] = curves[i].size();
    }

    // The curve array vector will deallocate all memory by itself.
    cvpoint_array_vec_t pp( num_curves );

    CvPoint** curve_array = new CvPoint*[num_curves];

    for( std::size_t i = 0; i < num_curves; ++i )
    {
        pp[i] = make_cvPoint_array( curves[i] );

        curve_array[i] = pp[i].get();
    }

    cvPolyLine( ipl_image.get()
                , curve_array  // needs to be pointer to C array of CvPoints.
                , num_points_per_curve.get()// int array that contains number of points of each curve.
                , curves.size()
                , is_closed
                , make_cvScalar( color )
                , line_width             );

}
static GstFlowReturn
kms_crowd_detector_transform_frame_ip (GstVideoFilter * filter,
    GstVideoFrame * frame)
{
  KmsCrowdDetector *crowddetector = KMS_CROWD_DETECTOR (filter);
  GstMapInfo info;

  kms_crowd_detector_initialize_images (crowddetector, frame);
  if ((crowddetector->priv->num_rois == 0)
      && (crowddetector->priv->rois != NULL)) {
    kms_crowd_detector_extract_rois (crowddetector);
  }
  if (crowddetector->priv->pixels_rois_counted == TRUE &&
      crowddetector->priv->actual_image != NULL) {
    kms_crowd_detector_count_num_pixels_rois (crowddetector);
    crowddetector->priv->pixels_rois_counted = FALSE;
  }
  gst_buffer_map (frame->buffer, &info, GST_MAP_READ);
  crowddetector->priv->actual_image->imageData = (char *) info.data;

  IplImage *frame_actual_gray =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (frame_actual_gray);

  IplImage *actual_lbp =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (actual_lbp);

  IplImage *lbp_temporal_result =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (lbp_temporal_result);

  IplImage *add_lbps_result =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (add_lbps_result);

  IplImage *lbps_alpha_result_rgb =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 3);

  cvSet (lbps_alpha_result_rgb, CV_RGB (0, 0, 0), 0);

  IplImage *actual_image_masked =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height), IPL_DEPTH_8U, 1);

  cvZero (actual_image_masked);

  IplImage *substract_background_to_actual =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (substract_background_to_actual);

  IplImage *low_speed_map =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (low_speed_map);

  IplImage *high_speed_map =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (high_speed_map);

  IplImage *actual_motion =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 3);

  cvSet (actual_motion, CV_RGB (0, 0, 0), 0);

  IplImage *binary_actual_motion =
      cvCreateImage (cvSize (crowddetector->priv->actual_image->width,
          crowddetector->priv->actual_image->height),
      IPL_DEPTH_8U, 1);

  cvZero (binary_actual_motion);

  uint8_t *low_speed_pointer;
  uint8_t *low_speed_pointer_aux;
  uint8_t *high_speed_pointer;
  uint8_t *high_speed_pointer_aux;
  uint8_t *actual_motion_pointer;
  uint8_t *actual_motion_pointer_aux;
  uint8_t *binary_actual_motion_pointer;
  uint8_t *binary_actual_motion_pointer_aux;

  int w, h;

  if (crowddetector->priv->num_rois != 0) {
    cvFillPoly (actual_image_masked, crowddetector->priv->curves,
        crowddetector->priv->n_points, crowddetector->priv->num_rois,
        cvScalar (255, 255, 255, 0), CV_AA, 0);
  }
  cvCvtColor (crowddetector->priv->actual_image, frame_actual_gray,
      CV_BGR2GRAY);
  kms_crowd_detector_mask_image (frame_actual_gray, actual_image_masked, 0);

  if (crowddetector->priv->background == NULL) {
    cvCopy (frame_actual_gray, crowddetector->priv->background, 0);
  } else {
    cvAddWeighted (crowddetector->priv->background, BACKGROUND_ADD_RATIO,
        frame_actual_gray, 1 - BACKGROUND_ADD_RATIO, 0,
        crowddetector->priv->background);
  }

  kms_crowd_detector_compute_temporal_lbp (frame_actual_gray, actual_lbp,
      actual_lbp, FALSE);
  kms_crowd_detector_compute_temporal_lbp (frame_actual_gray,
      lbp_temporal_result, crowddetector->priv->frame_previous_gray, TRUE);
  cvAddWeighted (crowddetector->priv->previous_lbp, LBPS_ADD_RATIO, actual_lbp,
      (1 - LBPS_ADD_RATIO), 0, add_lbps_result);
  cvSub (crowddetector->priv->previous_lbp, actual_lbp, add_lbps_result, 0);
  cvThreshold (add_lbps_result, add_lbps_result, 70.0, 255.0, CV_THRESH_OTSU);
  cvNot (add_lbps_result, add_lbps_result);
  cvErode (add_lbps_result, add_lbps_result, 0, 4);
  cvDilate (add_lbps_result, add_lbps_result, 0, 11);
  cvErode (add_lbps_result, add_lbps_result, 0, 3);
  cvCvtColor (add_lbps_result, lbps_alpha_result_rgb, CV_GRAY2BGR);
  cvCopy (actual_lbp, crowddetector->priv->previous_lbp, 0);
  cvCopy (frame_actual_gray, crowddetector->priv->frame_previous_gray, 0);

  if (crowddetector->priv->acumulated_lbp == NULL) {
    cvCopy (add_lbps_result, crowddetector->priv->acumulated_lbp, 0);
  } else {
    cvAddWeighted (crowddetector->priv->acumulated_lbp, TEMPORAL_LBPS_ADD_RATIO,
        add_lbps_result, 1 - TEMPORAL_LBPS_ADD_RATIO, 0,
        crowddetector->priv->acumulated_lbp);
  }

  cvThreshold (crowddetector->priv->acumulated_lbp, high_speed_map,
      150.0, 255.0, CV_THRESH_BINARY);
  cvSmooth (high_speed_map, high_speed_map, CV_MEDIAN, 3, 0, 0.0, 0.0);
  kms_crowd_detector_substract_background (frame_actual_gray,
      crowddetector->priv->background, substract_background_to_actual);
  cvThreshold (substract_background_to_actual, substract_background_to_actual,
      70.0, 255.0, CV_THRESH_OTSU);

  cvCanny (substract_background_to_actual,
      substract_background_to_actual, 70.0, 150.0, 3);

  if (crowddetector->priv->acumulated_edges == NULL) {
    cvCopy (substract_background_to_actual,
        crowddetector->priv->acumulated_edges, 0);
  } else {
    cvAddWeighted (crowddetector->priv->acumulated_edges, EDGES_ADD_RATIO,
        substract_background_to_actual, 1 - EDGES_ADD_RATIO, 0,
        crowddetector->priv->acumulated_edges);
  }

  kms_crowd_detector_process_edges_image (crowddetector, low_speed_map, 3);
  cvErode (low_speed_map, low_speed_map, 0, 1);

  low_speed_pointer = (uint8_t *) low_speed_map->imageData;
  high_speed_pointer = (uint8_t *) high_speed_map->imageData;
  actual_motion_pointer = (uint8_t *) actual_motion->imageData;
  binary_actual_motion_pointer = (uint8_t *) binary_actual_motion->imageData;

  for (h = 0; h < low_speed_map->height; h++) {
    low_speed_pointer_aux = low_speed_pointer;
    high_speed_pointer_aux = high_speed_pointer;
    actual_motion_pointer_aux = actual_motion_pointer;
    binary_actual_motion_pointer_aux = binary_actual_motion_pointer;
    for (w = 0; w < low_speed_map->width; w++) {
      if (*high_speed_pointer_aux == 0) {
        actual_motion_pointer_aux[0] = 255;
        binary_actual_motion_pointer_aux[0] = 255;
      }
      if (*low_speed_pointer_aux == 255) {
        *actual_motion_pointer_aux = 0;
        actual_motion_pointer_aux[2] = 255;
        binary_actual_motion_pointer_aux[0] = 255;
      } else if (*high_speed_pointer_aux == 0) {
        actual_motion_pointer_aux[0] = 255;
      }
      low_speed_pointer_aux++;
      high_speed_pointer_aux++;
      actual_motion_pointer_aux = actual_motion_pointer_aux + 3;
      binary_actual_motion_pointer_aux++;
    }
    low_speed_pointer += low_speed_map->widthStep;
    high_speed_pointer += high_speed_map->widthStep;
    actual_motion_pointer += actual_motion->widthStep;
    binary_actual_motion_pointer += binary_actual_motion->widthStep;
  }

  int curve;

  for (curve = 0; curve < crowddetector->priv->num_rois; curve++) {

    if (crowddetector->priv->rois_data[curve].send_optical_flow_event == TRUE) {

      CvRect container =
          kms_crowd_detector_get_square_roi_contaniner (crowddetector, curve);

      cvSetImageROI (crowddetector->priv->actual_image, container);
      cvSetImageROI (crowddetector->priv->previous_image, container);
      cvSetImageROI (actual_motion, container);

      kms_crowd_detector_compute_optical_flow (crowddetector,
          binary_actual_motion, container, curve);

      cvResetImageROI (crowddetector->priv->actual_image);
      cvResetImageROI (crowddetector->priv->previous_image);
    }
  }

  {
    uint8_t *orig_row_pointer =
        (uint8_t *) crowddetector->priv->actual_image->imageData;
    uint8_t *overlay_row_pointer = (uint8_t *) actual_motion->imageData;

    for (h = 0; h < crowddetector->priv->actual_image->height; h++) {
      uint8_t *orig_column_pointer = orig_row_pointer;
      uint8_t *overlay_column_pointer = overlay_row_pointer;

      for (w = 0; w < crowddetector->priv->actual_image->width; w++) {
        int c;

        for (c = 0; c < crowddetector->priv->actual_image->nChannels; c++) {
          if (overlay_column_pointer[c] != 0) {
            orig_column_pointer[c] = overlay_column_pointer[c];
          }
        }

        orig_column_pointer += crowddetector->priv->actual_image->nChannels;
        overlay_column_pointer += actual_motion->nChannels;
      }
      orig_row_pointer += crowddetector->priv->actual_image->widthStep;
      overlay_row_pointer += actual_motion->widthStep;
    }
  }

  if (crowddetector->priv->num_rois != 0) {
    cvPolyLine (crowddetector->priv->actual_image, crowddetector->priv->curves,
        crowddetector->priv->n_points, crowddetector->priv->num_rois, 1,
        cvScalar (255, 255, 255, 0), 1, 8, 0);
  }

  cvNot (high_speed_map, high_speed_map);
  kms_crowd_detector_roi_analysis (crowddetector, low_speed_map,
      high_speed_map);

  cvReleaseImage (&frame_actual_gray);
  cvReleaseImage (&actual_lbp);
  cvReleaseImage (&lbp_temporal_result);
  cvReleaseImage (&add_lbps_result);
  cvReleaseImage (&lbps_alpha_result_rgb);
  cvReleaseImage (&actual_image_masked);
  cvReleaseImage (&substract_background_to_actual);
  cvReleaseImage (&low_speed_map);
  cvReleaseImage (&high_speed_map);
  cvReleaseImage (&actual_motion);
  cvReleaseImage (&binary_actual_motion);

  gst_buffer_unmap (frame->buffer, &info);

  return GST_FLOW_OK;
}
Пример #18
0
void Nui_DrawSkeletonSegment( NUI_SKELETON_DATA * pSkel, int numJoints, ... )
{
    va_list vl;
    va_start(vl,numJoints);
    vector<CvPoint*> segmentPositions;
    vector<CvPoint> pt;
    //CvPoint segmentPositions[1][NUI_SKELETON_POSITION_COUNT];
    int segmentPositionsCount = 0;
    vector<int> polylinePointCounts;
    //int polylinePointCounts[NUI_SKELETON_POSITION_COUNT];
    int numPolylines = 0;
    int currentPointCount = 0;

    // Note the loop condition: We intentionally run one iteration beyond the
    // last element in the joint list, so we can properly end the final polyline.

    for (int iJoint = 0; iJoint <= numJoints; iJoint++)
    {
        if (iJoint < numJoints)
        {
            NUI_SKELETON_POSITION_INDEX jointIndex = va_arg(vl,NUI_SKELETON_POSITION_INDEX);

            if (pSkel->eSkeletonPositionTrackingState[jointIndex] != NUI_SKELETON_POSITION_NOT_TRACKED)
            {
                // This joint is tracked: add it to the array of segment positions.
              CvPoint t;
              t.x = m_Points[jointIndex].x;
              t.y = m_Points[jointIndex].y;
              pt.push_back(t);
              currentPointCount++;

                // Fully processed the current joint; move on to the next one

              continue;
            }
        }

        // If we fall through to here, we're either beyond the last joint, or
        // the current joint is not tracked: end the current polyline here.

        if (currentPointCount > 1)
        {
            // Current polyline already has at least two points: save the count.
          segmentPositions.push_back(&pt[0]);
          polylinePointCounts.push_back(currentPointCount);
        }
        else if (currentPointCount == 1)
        {
            // Current polyline has only one point: ignore it.

          pt.clear();
        }
        currentPointCount = 0;
    }

#ifdef _DEBUG
    // We should end up with no more points in segmentPositions than the
    // original number of joints.

    assert(segmentPositionsCount <= numJoints);

    int totalPointCount = 0;
    for (int i = 0; i < numPolylines; i++)
    {
        // Each polyline should contain at least two points.
    
        assert(polylinePointCounts[i] > 1);

        totalPointCount += polylinePointCounts[i];
    }

    // Total number of points in all polylines should be the same as number
    // of points in segmentPositions.
    
    assert(totalPointCount == segmentPositionsCount);
#endif

    if (numPolylines > 0)
    {
      CvScalar color={0,255,0};
      
      cvPolyLine(kinect_skeleton_image,&segmentPositions[0],&polylinePointCounts[0],numPolylines,0,color,4);
     //   PolyPolyline(m_SkeletonDC, segmentPositions, polylinePointCounts, numPolylines);
    }

    va_end(vl);
}
Пример #19
0
/*-------------------------------------------------------------------------
功能:画多边形函数
输入:图像指针
输出:无
date: 2014-02-11
---------------------------------------------------------------------------*/
void draw_multi(IplImage *img)
{
	cvPolyLine(img, pt, arr, 1, 1, CV_RGB(250,0,0)); //红色多边形
}
Пример #20
0
// the function draws all the squares in the image and crop and save images
void drawSquaresAndCrop(char *pFileName, IplImage* imgFilter, IplImage* img, CvSeq* squares )
{
    CvSeqReader reader;
    IplImage* cpy = cvCloneImage( imgFilter );
	IplImage* cpyc = cvCloneImage( imgFilter );
    int i;
	char sFileNameCroped[255];
    
    // initialize reader of the sequence
    cvStartReadSeq( squares, &reader, 0 );
    
    // read 4 sequence elements at a time (all vertices of a square)
    for(int iCnt=0, i = 0; i < squares->total; i += 4,iCnt++ )
    {
        CvPoint pt[4], *rect = pt;
        int count = 4;
        
        // read 4 vertices
        CV_READ_SEQ_ELEM( pt[0], reader );
        CV_READ_SEQ_ELEM( pt[1], reader );
        CV_READ_SEQ_ELEM( pt[2], reader );
        CV_READ_SEQ_ELEM( pt[3], reader );
        
        // draw the square as a closed polyline 
        cvPolyLine( cpy, &rect, &count, 1, 1, CV_RGB(0,255,0), 3, CV_AA, 0 );

		// Get Area to crop
		CvRect rc = GetRect(pt);
		// Filter the area full image
		if (abs(rc.width-img->width)>POINTS_NEAR ||
			abs(rc.height-img->height)>POINTS_NEAR){

			// Draw area
			CvPoint pt1, pt2;
			pt1.x = rc.x;
			pt1.y = rc.y;
			pt2.x = pt1.x+rc.width;
			pt2.y = pt1.y+rc.height;
			cvRectangle(cpy, pt1, pt2, CV_RGB(0,0,255),2);

			
			// sets the Region of Interest 
			// Note that the rectangle area has to be __INSIDE__ the image 
			cvSetImageROI(cpyc, rc);
			// create destination image 
			// Note that cvGetSize will return the width and the height of ROI 
			IplImage *img1 = cvCreateImage(cvGetSize(cpyc), 
										   cpyc->depth, 
										   cpyc->nChannels);
			 
			// copy subimage 
			cvCopy(cpyc, img1, NULL);		 
			// save file
			char stype[32];
			char sFile[255];
			strcpy(sFile, pFileName);
			strcpy(stype, &(pFileName[strlen(pFileName)-3]));
			sFile[strlen(pFileName)-4]=NULL;
			
			sprintf(sFileNameCroped, "%s_%d.%s", sFile,iCnt,stype);
			cvSaveImage(sFileNameCroped, img1);

			// always reset the Region of Interest
			cvResetImageROI(img1);    
		}
	}
    
    // show the resultant image
    cvShowImage( wndname, cpy );
    cvReleaseImage( &cpy );
	cvReleaseImage( &cpyc );
}
Пример #21
0
static int drawing_test()
{
    static int read_params = 0;
    static int read = 0;
    const int channel = 3;
    CvSize size = cvSize(600, 300);

    int i, j;
    int Errors = 0;

    if( !read_params )
    {
        read_params = 1;

        trsCaseRead( &read, "/n/y", "y", "Read from file ?" );
    }
    // Create image
    IplImage* image = cvCreateImage( size, IPL_DEPTH_8U, channel );

    // cvLine
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
        CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );

        cvLine( image, p1, p2, CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvLine", read );

    // cvLineAA
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
        CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );

        cvLine( image, p1, p2, CV_RGB(178+i, 255-i, i), 1, CV_AA, 0 );
    }
    //Errors += ProcessImage( image, "cvLineAA", read );

    // cvRectangle
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
        CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );

        cvRectangle( image, p1, p2, CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvRectangle", read );

#if 0
        named_window( "Diff", 0 );
#endif

    // cvCircle
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i * 3, i * 2 );
        CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );

        cvCircle( image, p1, i, CV_RGB(178+i, 255-i, i), i % 10 );
        cvCircle( image, p2, i, CV_RGB(178+i, 255-i, i), i % 10 );

#if 0
        show_iplimage( "Diff", image );
        wait_key(0);
#endif
    }
    Errors += ProcessImage( image, "cvCircle", read );

    // cvCircleAA
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i * 3, i * 2 );
        CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );

        cvCircleAA( image, p1, i, RGB(i, 255 - i, 178 + i), 0 );
        cvCircleAA( image, p2, i, RGB(i, 255 - i, 178 + i), 0 );
    }
    Errors += ProcessImage( image, "cvCircleAA", read );

    // cvEllipse
    cvZero( image );

    for( i = 10; i < 100; i += 10 )
    {
        CvPoint p1 = cvPoint( i * 6, i * 3 );
        CvSize axes = cvSize( i * 3, i * 2 );

        cvEllipse( image, p1, axes,
                   180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
                   CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvEllipse", read );

    // cvEllipseAA
    cvZero( image );

    for( i = 10; i < 100; i += 10 )
    {
        CvPoint p1 = cvPoint( i * 6, i * 3 );
        CvSize axes = cvSize( i * 3, i * 2 );

        cvEllipseAA( image, p1, axes,
                   180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
                   RGB(i, 255 - i, 178 + i), i % 10 );
    }
    Errors += ProcessImage( image, "cvEllipseAA", read );

    // cvFillConvexPoly
    cvZero( image );

    for( j = 0; j < 5; j++ )
        for( i = 0; i < 100; i += 10 )
        {
            CvPoint p[4] = {{ j * 100 - 10, i }, { j * 100 + 10, i },
                            { j * 100 + 30, i * 2 }, { j * 100 + 170, i * 3 }};
            cvFillConvexPoly( image, p, 4, CV_RGB(178+i, 255-i, i) );

        }
    Errors += ProcessImage( image, "cvFillConvexPoly", read );

    // cvFillPoly
    cvZero( image );

    for( i = 0; i < 100; i += 10 )
    {
        CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
        CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
        CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
        CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
        CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};

        CvPoint* p[] = {p0, p1, p2, p3, p4};

        int n[] = {4, 4, 4, 4, 4};
        cvFillPoly( image, p, n, 5, CV_RGB(178+i, 255-i, i) );
    }
    Errors += ProcessImage( image, "cvFillPoly", read );

    // cvPolyLine
    cvZero( image );

    for( i = 0; i < 100; i += 10 )
    {
        CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
        CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
        CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
        CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
        CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};

        CvPoint* p[] = {p0, p1, p2, p3, p4};

        int n[] = {4, 4, 4, 4, 4};
        cvPolyLine( image, p, n, 5, 1, CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvPolyLine", read );

    // cvPolyLineAA
    cvZero( image );

    for( i = 0; i < 100; i += 10 )
    {
        CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
        CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
        CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
        CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
        CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};

        CvPoint* p[] = {p0, p1, p2, p3, p4};

        int n[] = {4, 4, 4, 4, 4};
        cvPolyLineAA( image, p, n, 5, 1, RGB(i, 255 - i, 178 + i), 0 );
    }
    Errors += ProcessImage( image, "cvPolyLineAA", read );

    // cvPolyLineAA
    cvZero( image );

    for( i = 1; i < 10; i++ )
    {
        CvFont font;
        cvInitFont( &font, CV_FONT_VECTOR0,
                    (double)i / 5, (double)i / 5, (double)i / 10, i );
        cvPutText( image, "privet. this is test. :)", cvPoint(0, i * 20), &font, CV_RGB(178+i, 255-i, i) );
    }
    Errors += ProcessImage( image, "cvPutText", read );

    cvReleaseImage( &image );

    return Errors ? trsResult( TRS_FAIL, "errors" ) : trsResult( TRS_OK, "ok" );
}