Пример #1
0
void AAMFit::CreateStat( IplImage *pFrame, int pMode, bool pDrawNumbers, CvScalar pRGB )
{
	CvFont font;
	char text[20];

	cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX, 0.1, 1.0, 0, 1, CV_AA );
	//_model->Draw(pFrame, pMode);

	if( _smoothedImagePoints.empty() )
	{
		for( int i = 0; i < _imagePoints.size(); i++ )
		{
			cvCircle( pFrame, cvPoint( _imagePoints[i].x, _imagePoints[i].y), 3, pRGB, -1 );

			if( pDrawNumbers )
			{
				sprintf( text, "%d", i );
				cvPutText( pFrame, text, cvPoint(_imagePoints[i].x, _imagePoints[i].y), &font, cvScalar(255, 255, 255, 0) );
			}
		}
	}
	else
	{
		for( int i = 0; i < _smoothedImagePoints.size(); i++ )
		{
			cvCircle( pFrame, cvPoint( _smoothedImagePoints[i].x, _smoothedImagePoints[i].y), 3, pRGB, -1 );

			if( pDrawNumbers )
			{
				sprintf( text, "%d", i );
				cvPutText( pFrame, text, cvPoint(_smoothedImagePoints[i].x, _smoothedImagePoints[i].y), &font, cvScalar(255, 255, 255, 0) );
			}
		}
	}
}
Пример #2
0
void KfieldGui::DrawObservations(belief Belief,vector<KObservationModel> & Observation) {
	CvPoint pt1, pt2;
	unsigned int i;
	CvScalar currentColor;
	bool ambigius=false;

	pthread_mutex_lock(&lock);
	for (i = 0; i < Observation.size(); i++) {

		if (Observation[i].Feature.id == "YellowLeft") {// "YellowLeft"
			currentColor = color["lightyellow"];
		} else if (Observation[i].Feature.id == "YellowRight") { //"YellowRight"
			currentColor = color["lightyellow"];
		} else if (Observation[i].Feature.id == "SkyblueLeft") {// "YellowLeft"
			currentColor = color["lightblue"];
		} else if (Observation[i].Feature.id == "SkyblueRight") { //"YellowRight"
			currentColor = color["lightblue"];
		} else if (Observation[i].Feature.id == "Skyblue") { //Ambigious GoalPost
			currentColor = color["darkblue"];
			ambigius = true;
		} else if (Observation[i].Feature.id == "Yellow") { //Ambigious GoalPost
			currentColor = color["darkyellow"];
			ambigius = true;
		}


		for(int j=1; j >(ambigius)?-2:0;j=j-2){ //If we have abigious goal then plot both goal posts
			pt1.x = (Observation[i].Feature.x + (2 * margintoline + field_width) / 2.0) / scale;
			pt1.y = (-Observation[i].Feature.y*j + (2 * margintoline + field_height) / 2.0) / scale;

			cvCircle(field, pt1, Observation[i].Distance.val / scale, currentColor, 0, CV_AA, 0);
			cvCircle(field, pt1, rint(Observation[i].Distance.val / scale), currentColor, 0, CV_AA, 0);

			cout << "Real Distance " << Observation[i].Distance.val << endl;

			if ((Observation[i].Distance.val + Observation[i].Distance.Edev) > 0)
				cvCircle(field, pt1, (Observation[i].Distance.val + Observation[i].Distance.Edev) / scale, currentColor, 0, CV_AA, 0);
			if ((Observation[i].Distance.val - Observation[i].Distance.Edev) > 0)
				cvCircle(field, pt1, (Observation[i].Distance.val - Observation[i].Distance.Edev) / scale, currentColor, 0, CV_AA, 0);

			pt2.x = pt1.x - (Observation[i].Distance.val / scale) * cos(-(Observation[i].Bearing.val+Belief.theta));
			pt2.y = pt1.y - (Observation[i].Distance.val / scale) * sin(-(Observation[i].Bearing.val+Belief.theta));

			cvLine(field, pt1, pt2, currentColor, 0, CV_AA, 0);
		}

		if (i == 0) {
			string tmp = Kutils::to_string(Observation[i].Distance.val);
			cvPutText(field, tmp.c_str(), cvPoint((2 * margintoline + field_width - 200) / scale, (2 * margintoline + field_height + 650) / scale), &font, currentColor);
		}

		if (i == 1) {
			string tmp = Kutils::to_string(Observation[i].Distance.val);
			cvPutText(field, tmp.c_str(), cvPoint((2 * margintoline + field_width - 200) / scale, (2 * margintoline + field_height + 850) / scale), &font, currentColor);
		}
	}
	pthread_mutex_unlock(&lock);

}
// Draw graphs      -- todo, adjust to fit in window
void Painting::drawGraph()
{
    // Paint the canvas white
    cvZero(mImage);
    cvRectangleR(mImage,cvRect(0,0,500,500),cvScalar(255,255,255), -1);

    CvFont font;
    double hScale=0.5;
    double vScale=0.5;
    int    lineWidth=1;
    cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale,vScale,0,lineWidth);

    // Add text to canvas
    cvPutText (mImage,"Left",cvPoint(20,50), &font, cvScalar(200,0,0));
    cvPutText (mImage,"Right",cvPoint(420,50), &font, cvScalar(0,200,0));

    // Iterate the vector of data and center the selected objects
    if(mData.size())
    {
        int xScale = 200;
        int yScale = 20;
        int xOffSet = 250 - mData[mSelect].timeStamp * xScale;
        int yOffSet1 = 240 + mData[mSelect].pulsefreq * yScale;
        int yOffSet2 = 250 + mData[mSelect].blinkingfreq * yScale;
        int yOffSet3 = 260 + mData[mSelect].breathingfreq * yScale;
        int t = 1; //thick

        if(mSelect == 0)
            t = -1;

        drawCircle(mImage,cvPoint(mData[0].timeStamp * xScale + xOffSet,yOffSet1 - mData[0].pulsefreq * yScale),0,t);
        drawCircle(mImage,cvPoint(mData[0].timeStamp * xScale + xOffSet,yOffSet2 - mData[0].blinkingfreq * yScale),1,t);
        drawCircle(mImage,cvPoint(mData[0].timeStamp * xScale + xOffSet,yOffSet3 - mData[0].breathingfreq * yScale),2,t);

        for(unsigned int i = 1; i<mData.size(); i++)
        {
            int thick = 1;
            if((unsigned)mSelect == i)
                thick = -1;
            // Pulse
            drawCircle(mImage,cvPoint(mData[i].timeStamp * xScale + xOffSet, yOffSet1 - mData[i].pulsefreq * yScale),0,thick);
            cvLine(mImage,cvPoint(mData[i].timeStamp * xScale + xOffSet, yOffSet1 - mData[i].pulsefreq * yScale),
                   cvPoint(mData[i-1].timeStamp * xScale + xOffSet, yOffSet1 - mData[i-1].pulsefreq * yScale),cvScalar(0,0,255));
            // Blinking
            drawCircle(mImage,cvPoint(mData[i].timeStamp * xScale + xOffSet, yOffSet2 - mData[i].blinkingfreq * yScale),1,thick);
            cvLine(mImage,cvPoint(mData[i].timeStamp * xScale + xOffSet, yOffSet2 - mData[i].blinkingfreq * yScale),
                   cvPoint(mData[i-1].timeStamp * xScale + xOffSet, yOffSet2 - mData[i-1].blinkingfreq * yScale),cvScalar(0,255,0));
            // Breathing
            drawCircle(mImage,cvPoint(mData[i].timeStamp * xScale + xOffSet, yOffSet3 - mData[i].breathingfreq * yScale),2,thick);
            cvLine(mImage,cvPoint(mData[i].timeStamp * xScale + xOffSet, yOffSet3 - mData[i].breathingfreq * yScale),
                   cvPoint(mData[i-1].timeStamp * xScale + xOffSet, yOffSet3 - mData[i-1].breathingfreq * yScale),cvScalar(255,0,0));
        }
    }

    cvShowImage(WindowName, mImage);

}
Пример #4
0
   /* draw to video canvas */
   static void video (
         GtkWidget      *widget,
         GdkEventExpose *eev){

      //gtk_widget_queue_draw(GTK_WIDGET(widget));

      if(!start) return;

      if(cv_image!=NULL){

        double t =  microtime();

        /* vypsání ladícího textu */
        CvFont font;
        double hScale=0.5;
        double vScale=0.5;
        int lineWidth=1;
        char buffer[125];

        cvFlip(cv_image, cv_image, 1);

         cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale, vScale, 0, lineWidth);
         sprintf(buffer,"Treshold %d/255 [key m,n]", treshold);
         cvPutText (cv_image, buffer, cvPoint(10, 20), &font, cvScalar(0, 255, 0));
         cvLine(cv_image, cvPoint(260,15), cvPoint(260 + treshold,15), cvScalar(0, 255, 0), 10, 4);

         sprintf(buffer,"Timer: %f | %f | %f | %f", timer[0], timer[1], timer[2], timer[3]);
         cvPutText (cv_image,buffer,cvPoint(10,40), &font, cvScalar(255, 0, 0));
         sprintf(buffer,"Fps: %d ", fps);
         cvPutText (cv_image,buffer,cvPoint(10,60), &font, cvScalar(255, 0, 0));

         //převedení opencv do gtk
         GdkPixbuf * pix = gdk_pixbuf_new_from_data(
               (guchar*)cv_image->imageData,
               GDK_COLORSPACE_RGB,
               FALSE,
               cv_image->depth,
               cv_image->width,
               cv_image->height,
               cv_image->widthStep,
               NULL,
               NULL);
          //gtkImg = gtk_image_new_from_pixbuf (pix);
         gdk_draw_pixbuf (widget->window,
                      widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                      pix,
                      0, 0, 0, 0, 640, 480, GDK_RGB_DITHER_NONE, 0, 0 );
         //gtk_widget_queue_draw(widget);
         gdk_pixbuf_unref (pix);
         
         timer[2] =  microtime() - t;
      } else {
         //printf("ERROR: Video nebylo načteno.\n");
      }

      currently_framing = 0;
   }
Пример #5
0
// TODO: what the f**k are these messy functions. Fix them.
void drawText(IplImage *img, const char *text, CvPoint at, CvScalar color, CvFont *font = NULL) {
    if (!font) {
        CvFont font1;
        cvInitFont(&font1, CV_FONT_HERSHEY_DUPLEX, 1.0, 0.8, 0.2, 1, 8);
        cvPutText(img, text, at, &font1, color);
    } else {
        cvPutText(img, text, at, font, color);
    }
}
Пример #6
0
int main (int argc, char **argv)
{
    int width=960, height=640;
    IplImage *img=0;
    double c, f;
    f = cvGetTickFrequency()*1000;
    
    int cx = width/2;
    int cy = height/2;
    double radius = 100;
    double angle = 0;
    CvScalar color = cvScalarAll(255);
    
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 1.0, 1.0, 1, CV_AA);
    
    cvNamedWindow ("hexagon", CV_WINDOW_AUTOSIZE);
    while (1) {
        
        // (1)allocate and initialize an image
        img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
        if(img == 0) return -1;
        cvZero(img);
        
        // (2) draw hexagon
        c = cvGetTickCount();
        myHexagon(img, cx, cy, radius, angle, color);
        printf("%fms\n", (cvGetTickCount()-c)/f);
        
        // (3)show the iamge, and press some key
        cvPutText(img, "Coordinate Right(D) Left(A) Up(W) Down(X)", cvPoint(10, 20), &font, cvScalarAll(255));
        cvPutText(img, "Rotate Right(R) Left(E)", cvPoint(10, 40), &font, cvScalarAll(255));
        cvPutText(img, "Radius Big(V) Small(C)", cvPoint(10, 60), &font, cvScalarAll(255));
        cvPutText(img, "Quit(Q, esc)", cvPoint(10, 80), &font, cvScalarAll(255));
        char s[64];
        sprintf(s, "cx:%d cy:%d radius:%f angle:%f", cx, cy, radius, angle);
        cvPutText(img, s, cvPoint(10, 110), &font, cvScalarAll(255));
        
        cvShowImage ("hexagon", img);
        char key = cvWaitKey (0);
        if (key == 27 || key == 'q') break;
        else if (key == 'r') angle += 5;
        else if (key == 'e') angle -= 5;
        else if (key == 'a') cx -= 5;
        else if (key == 'd') cx += 5;
        else if (key == 'w') cy -= 5;
        else if (key == 'x') cy += 5;
        else if (key == 'v') radius += 5;
        else if (key == 'c') radius -= 5;
    }
    
    cvDestroyWindow("hexagon");
    cvReleaseImage(&img);
    
    return 0;
}
Пример #7
0
void Bot::make()
{
	camera->update();
	if(camera->getFrame()){
		//
		// получаем кадр с камеры
		//
		if(image==0){
			image = cvCloneImage(camera->getFrame());
		}
		else{
			cvCopy(camera->getFrame(), image);
		}

		// для хранения центра объекта
		CvPoint2D32f point;

		//
		// передаём кадр на обработку детектору
		//
		bool result = detector->getCenter( image, point, BOT_THRESHOLD);

		char buf[128]; // для вывода информации

		if(result){
			//
			// объект обнаружен
			//

			printf("[i][Bot] point: %.2f : %.2f \n", point.x, point.y);

			if(gimbal){
				gimbal->make( cvPoint(image->width/2, image->height/2), cvPointFrom32f(point) );
			}

			// отметим центр
			cvCircle(image, cvPointFrom32f(point), 3, CV_RGB(0, 255, 0), 2);

			// выводим сообщение в верхнем левом углу картинки
			sprintf(buf, "Object detected: %.2f : %.2f", point.x, point.y);
			cvPutText(image, buf, cvPoint(10, 20), &font, CV_RGB(0, 255, 0));
		}
		else{
			//
			// объект не обнаружен
			//

			// выводим сообщение в верхнем левом углу картинки
			sprintf(buf, "Cant find object!");
			cvPutText(image, buf, cvPoint(10, 20), &font, CV_RGB(255 , 0, 0));
		}

		cvShowImage(window_name, image);
	}
}
Пример #8
0
void KfieldGui::drawErrors(float DistError, float RotError) {
	pthread_mutex_lock(&lock);

	tmp = Kutils::to_string(DistError); // boost::lexical_cast<string>(Belief.confidence);
	cvPutText(field, tmp.c_str(), cvPoint((2 * margintoline + field_width - 200) / scale, (2 * margintoline + field_height + 650) / scale), &font, color["white"]);

	tmp = Kutils::to_string(RotError * TO_DEG);
	cvPutText(field, tmp.c_str(), cvPoint((2 * margintoline + field_width - 200) / scale, (2 * margintoline + field_height + 850) / scale), &font, color["white"]);
	pthread_mutex_unlock(&lock);

}
Пример #9
0
void KfieldGui::DisplayErrors(float DistError, float RotError) {
	pthread_mutex_lock(&lock);

	tmp = Kutils::to_string(DistError); // boost::lexical_cast<string>(Belief.confidence);
	cvPutText(field, tmp.c_str(), cvPoint((2 * 675.0 + 6050 - 200) / SCALE, (2 * 675.0 + 4050 + 650) / SCALE), &font, cvScalar(255, 255, 255));

	tmp = Kutils::to_string(RotError * TO_DEG);
	cvPutText(field, tmp.c_str(), cvPoint((2 * 675.0 + 6050 - 200) / SCALE, (2 * 675.0 + 4050 + 850) / SCALE), &font, cvScalar(255, 255, 255));
	pthread_mutex_unlock(&lock);

}
Пример #10
0
void EyeTracker::drawTrasholds()
{
	CvFont font;
	char s[20];
	sprintf(s, "HIGH THRESHOLD = %d", highThreshold);
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC, 1, 1, 0, 1);
	cvPutText(grayEyeImagePts, s, cvPoint(10, 40), &font, cvScalar(255, 255, 0));

	sprintf(s, "SQUARE THRESHOLD = %d", squareThreshold);
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC, 1, 1, 0, 1);
	cvPutText(grayEyeImagePts, s, cvPoint(10, 100), &font, cvScalar(255, 255, 0));
}
Пример #11
0
void draw_digit(int width, int x, int y, char *digit,
				IplImage *debug, CvFont *font)
{
	char text[3] = { digit[0] + 48, 0, 0 };
	if (text[0] > '9') {
		text[0] -= 10;
		text[1] = '.';
	}
	CvPoint origin = cvPoint(debug->width * x / width, debug->height - y);
	cvPutText(debug, text, origin, font, cvScalar(0, 0, 0, 255));
	origin.x--;
	cvPutText(debug, text, origin, font, cvScalar(0, 0, 255, 255));
}
Пример #12
0
void kalman::showlist(bool flag ,QPlainTextEdit *&plain)
{
	cvSet(img, cvScalar(255, 255, 255, 0));
	cvRectangle(img, cvPoint(rect.x, rect.y), cvPoint(rect.x + rect.width, rect.y + rect.height), cvScalar(255, 0, 0));

	CvFont font;
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5f, 0.5f, 0, 1, 8);
	if (nl->next)
	{
		node * p = nl->next;
		if (num >= 5 || flag)
		{
			while (p)
			{
				if (p->done)
				{
					cvCircle(img, cvPoint(p->x, p->y), 5, CV_RGB(255, 0, 0), 3);
 					p->done = false;
					p = p->next;
				}
				else
				{
					qDebug("dy:%d", p->dy);
					
					if (p->dy >= 10)
					{
						sum = sum - 1;
						qDebug("The Number : %d", sum);
						cvPutText(img, sum + "", cvPoint(0, 20), &font, cvScalar(0, 0, 255));

					}
					else if (p->dy <= -10)
					{
						sum++;
						qDebug("The Number : %d", sum);
						cvPutText(img, sum + "", cvPoint(0, 20), &font, cvScalar(0, 0, 255));
					}
					plain->appendPlainText("The Number :"+QString::number(sum));
					p = deleteNode(nl, p);
				}

			}
			num = 0;
		}
		else
		{
			num++;
		}
	}
	//cvShowImage("kalman",img);
 }
Пример #13
0
// called by the loop to actually grab the frames
int capture_image(int fd,CvFont *font, int *set_quality, IplImage* frame,CvMat *cvmat,char *capture_title,v4l2_buffer *buf, uint32_t *start_time, uint32_t *image_count) {

    // request a new frame
    if(-1 == xioctl(fd, VIDIOC_QBUF, buf)) {
        perror("Query Buffer");
        return 1;
    }

    // wait up to 2 sec for a new frame to arive
    fd_set fds;
    FD_ZERO(&fds);
    FD_SET(fd, &fds);
    struct timeval tv = {0};
    tv.tv_sec = 2;
    int r = select(fd+1, &fds, NULL, NULL, &tv);
    if(-1 == r) {
        perror("Waiting for Frame");
        return 1;
    }

    // read it
    if(-1 == xioctl(fd, VIDIOC_DQBUF, buf)) {
        perror("Retrieving Frame");
        return 1;
    }

    // convert v4l2 buffer to opencv image
    *cvmat = cvMat(height, width, CV_8UC3, (void*)buffer);
    frame = cvDecodeImage(cvmat, 1);

    // add title, reused tv from select-wait
    gettimeofday(&tv, NULL);
    time_t secs = time(0);
    struct tm *local = localtime(&secs);
    sprintf(capture_title, CAPTURE_PROTO, local->tm_hour, local->tm_min, local->tm_sec, (int)((unsigned long long)(tv.tv_usec) / 1000)%1000);

    (*image_count)++;
    printf("%s @ %2.2f fps\n",capture_title, round((float)(*image_count)*100/(time(0)-(*start_time)))/100 );
    cvPutText(frame, capture_title, cvPoint(22, 22), font, cvScalar(0,0,0,0));
    cvPutText(frame, capture_title, cvPoint(24, 24), font, cvScalar(200,200,200,0));

    // save to disk ... well RAM
    cvSaveImage("/dev/shm/mjpeg/cam_full.part.jpg", frame, set_quality);
    rename("/dev/shm/mjpeg/cam_full.part.jpg","/dev/shm/mjpeg/cam_full.jpg");

    // important to avoid mem leakage
    cvReleaseImage(&frame);

    return 0;
}
Пример #14
0
void PrintText(IplImage* img, char* text,CvScalar color, int l1_2){
	char* num=new char[20];
	itoa(fileCount,num,10);
//	strcat(text,num);
	if(l1_2==1){
		if(text!=NULL) cvPutText(img, text, cvPoint(10, 130), &font, color);
		else cvPutText(img, num, cvPoint(10, 130), &font, color);
	}
	else{
		if(text!=NULL) cvPutText(img, text, cvPoint(10, 230), &font, color);
		else cvPutText(img, num, cvPoint(10, 230), &font, color);
	}
	delete num;
}
Пример #15
0
void CvButtons::paintButtons(IplImage *img){
	vector<PushButton>::iterator it = buttonList.begin();
	while (it != buttonList.end()) {
		
		// Grab button variables:
		int x = it->x_pos;
		int y = it->y_pos;
		int w = it->width;
		int h = it->height;
		int x2 = x+w;
		int y2 = y+h;
		
		// Highlight mouseover position:
		if( mx >= x && mx <= x2 && my >= y && my <= y2 ){
			cvRectangle( img, cvPoint(x-4,y-4), cvPoint(x2+4,y2+4), C2, 1,CV_AA );
			
			// Check for mouse pressed event:
			if( me == CV_EVENT_LBUTTONDOWN/* || mf & CV_EVENT_FLAG_LBUTTON */){
				
				// Check if toggle button has to change state:
				if( it->toggle == 0 || it->toggle == 1 ) it->toggle = !it->toggle;
				
				// Call callback function:
				it->cb(it->toggle);
				
				// Draw confirmation rectangle:
				cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), C2,CV_FILLED,CV_AA );
				
				// Reset event (avoid flickering buttons):
				me = CV_EVENT_MOUSEMOVE;
			}
		}
		
		// Draw toggle state:
		if( it->toggle == 1 )
			cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), C2,CV_FILLED,CV_AA );
			
		// Draw button with text:
		cvRectangle( img, cvPoint(x,y), cvPoint(x2,y2), C2,1,CV_AA );
		if( it->toggle == 1 )
			cvPutText( img, it->text, cvPoint(x+5,y+15), &font, C1 );
		else
			cvPutText( img, it->text, cvPoint(x+5,y+15), &font, C2 );
        
        // Step to next button:
        it++;
	}
}
Пример #16
0
IplImage * showPoints(IplImage * img)
{
	int i,x1,y1,x2,y2;
	CvFont font; 
	cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, 0.5,0.5,0,1);

	for(i=0;i<line_set_cnt;i++)
	{
		x1 = point_val[line_set[i][0]][0];
		y1 = point_val[line_set[i][0]][1];
		x2 = point_val[line_set[i][1]][0];
		y2 = point_val[line_set[i][1]][1];
		
		if(x1>=0&&x2>=0)
		{
			cvLine(showim,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(100,100,100),POINT_RADIUS);
		}
	}

	for(i=0;i<point_set_cnt;i++)
	{
		if(point_val[i][0]>=0)
		{
			cvCircle(img,cvPoint(point_val[i][0],point_val[i][1]),POINT_RADIUS,cvScalar(0,0,255),-1);
			cvPutText(img,point_set[i],cvPoint(point_val[i][0]+POINT_RADIUS,point_val[i][1]),&font,CV_RGB(100,200,255));
		}
	}

	return img;
}
Пример #17
0
std::list<CvBox2D> PathObject::GetBounding(const IplImage * imgIn, IplImage * debugOut) const
{

    std::list<CvBox2D> blobList;
    if(imgIn == NULL) return blobList;
    IplImage * imgOut1 = GetMask(imgIn);
    //cvShowImage("imgout1",imgOut1);
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1,1);
    if(imgOut1)
    {
        blobList = Zebulon::Vision::VisionUtils::GetBlobBoxes(imgOut1,.001,.95);
        if (debugOut)
        {
            for(std::list<CvBox2D>::iterator it = blobList.begin(); it != blobList.end(); it++)
            {
//                CvPoint2D32f boxCorners[4];
//                cvBoxPoints(*it,boxCorners);

                std::ostringstream s;
                s << "(" << it->angle << ")";
                cvPutText(debugOut,s.str().c_str(),cvPointFrom32f(it->center),&font,mNearColor);
                Zebulon::Vision::VisionUtils::DrawSquare(debugOut,*it,mNearColor);
            }
        }
        cvReleaseImage(&imgOut1);
    }

    return blobList;

}
Пример #18
0
int main(int argc, char** argv) {
  CvCapture* capture = 0;
  IplImage* input = 0;
  IplImage* output = 0;
  int tick = 0, prev_tick = 0;
  double now = 0.0;
  CvFont font;
  char buffer[256];
  const char* windowName = "median";

  if (argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) {
    capture = cvCreateCameraCapture(argc == 2 ? argv[1][0] - '0' : 0);
  } else if (argc == 2) {
    capture = cvCreateFileCapture(argv[1]);
  }
  if (!capture) {
    fprintf(stderr, "ERROR: capture is NULL \n");
    return (-1);
  }

  cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE);
  cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0.0, 1, 0);
  input = cvQueryFrame(capture);
  if (!input) {
    fprintf(stderr, "Could not query frame...\n");
    return (-1);
  }
  output = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3);

  while (1) {
    input = cvQueryFrame(capture);
    if (!input) {
      fprintf(stderr, "Could not query frame...\n");
      break;
    }

    process(input, output);

    sprintf(buffer, "%3.1lfms", now / 1000);
    cvPutText(output, buffer, cvPoint(50, 150), &font, CV_RGB(255, 0, 0));

    cvShowImage(windowName, output);

    //If a certain key pressed
    if (cvWaitKey(10) >= 0) {
      break;
    }

    tick = cvGetTickCount();
    now = (tick - prev_tick) / cvGetTickFrequency();
    prev_tick = tick;
  }

  cvReleaseImage(&output);

  cvReleaseCapture(&capture);
  cvDestroyWindow(windowName);

  return 0;
}
Пример #19
0
void show_message(int predict_result, CvRect* r, IplImage* &imgDrawn)
{
    const char* actual_text;
	double hscale = 1.0;
	double vscale = 0.8;
	double shear = 0.2;
	int thickness = 2;
	int line_type = 8;
    
    if (predict_result==1) {
        actual_text="Welcome! Your Gender is Female";
    }else{
        if(predict_result==0)
            actual_text="Welcome! Your Gender is Male";
        else
            actual_text = "";
    }
    
	CvFont font1;
	cvInitFont(&font1,CV_FONT_HERSHEY_DUPLEX,hscale,vscale,shear,thickness,line_type);
    cvPutText(imgDrawn, actual_text,  cvPoint(r->x+10,r->y+10),&font1, CV_RGB(0,0,250));
    
    cvNamedWindow("Drawing_and_Text", 1);
	cvShowImage("Drawing_and_Text", imgDrawn);
}
Пример #20
0
        void run()
        {
        	cvCopyImage(*mInputImage, mOutputImage);
        	for (int i = mFromId; i < mToId; ++i) {
        		Craftag *tTag = mTags[i-mFromId];
				if (tTag->isPresent()){
					wykobi::point2d<float> tCenter = tTag->getCenter();
					wykobi::point2d<float> tTop = tCenter+tTag->getYUnit();
					wykobi::point2d<float> tRight = tCenter+tTag->getXUnit();

					static const int scShift = 2;
					static const float scPrecision = 1<<scShift;
					cvLine(mOutputImage, cvPoint(tCenter.x*scPrecision, tCenter.y*scPrecision), cvPoint(tTop.x*scPrecision, tTop.y*scPrecision), sColor, 1, CV_AA, scShift);
					cvLine(mOutputImage, cvPoint(tCenter.x*scPrecision, tCenter.y*scPrecision), cvPoint(tRight.x*scPrecision, tRight.y*scPrecision), sColor, 1, CV_AA, scShift);
					//char tText[256];
					//sprintf(tText, "%d:(%.2f,%.2f),(%.2f,%.2f),(%.2f,%.2f)", i, tCenter.x, tCenter.y, tTop.x, tTop.y, tRight.x, tRight.y);
					char tText[4+1];
					sprintf(tText, "%d", i);
					cvPutText(mOutputImage, tText, cvPoint(tCenter.x, tCenter.y), &mFont, sColor);

					CvPoint2D32f tCvCorners[4];
					CvWykobiBridge::convertQuad(wykobi::scale(scPrecision, scPrecision, tTag->getCorners()), tCvCorners);
					for (int i = 0; i < 4; ++i) {
						cvLine(mOutputImage, cvPointFrom32f(tCvCorners[i]), cvPointFrom32f(tCvCorners[(i+1)%4]), sColor, 1, CV_AA, scShift);
					}
				}
			}
        	cvShowImage("CraftagIdentifier", mOutputImage);
        	char tKeyPressed = cvWaitKey(1);
        	if (tKeyPressed == 'q') stop();
        }
Пример #21
0
void KfieldGui::draw_ball2(belief Belief, Ball Ball) {
	pthread_mutex_lock(&lock);

	CvPoint pt1, pt2;
	int radius = 0.065 / 2 * 1000.0 / scale;

	//double max = 0;
	float cos_theta = cos(Belief.theta);
	float sin_theta = sin(Belief.theta);

	pt1.x = Belief.x + 1000*(Ball.relativex()*cos_theta - Ball.relativey()*sin_theta);//Ball.dist() * 1000 * cos((Belief.theta + Ball.bearing()));
	pt1.y = Belief.y + 1000*(Ball.relativex()*sin_theta + Ball.relativey()*cos_theta);//Ball.dist() * 1000 * sin((Belief.theta + Ball.bearing()));

	cout << " ball relative X " << Ball.relativex() << " ball relative Y " << Ball.relativey() << endl;

	pt2.x = (pt1.x + (2 * margintoline + field_width) / 2.0) / scale;
	pt2.y = (-pt1.y + (2 * margintoline + field_height) / 2.0) / scale;

	cout << " Points in the field pt2.x " << pt2.x << " pt2.y " << pt2.y << endl;
	//cout << "Ball Dist" << Ball.dist() << " Ball diameter " << Ball.ball_diameter() << " Bearing " << Ball.bearing() << " pt x:" << pt1.x << " y: " << pt1.y << endl;
	//cvCopy(cleanfield, field);
	cvCircle(field, pt2, radius, color["red"], 0, CV_AA, 0);


	pt1.x = pt2.x + 100 *(Ball.relativexspeed()*cos_theta - Ball.relativeyspeed()*sin_theta);
	pt1.y = pt2.y - 100 *(Ball.relativexspeed()*sin_theta + Ball.relativeyspeed()*cos_theta);
	cvLine(field, pt1, pt2, CV_RGB(238, 254 , 348), 2, CV_AA, 0);

	//tmp = Kutils::to_string(Ball.dist());
	cvPutText(field, tmp.c_str(), cvPoint((2 * margintoline + field_width - 400) / scale, (2 * margintoline + field_height + 850) / scale), &font, color["orange"]);
	pthread_mutex_unlock(&lock);
	//cout << " Ball Drawn " << endl;
}
Пример #22
0
void Figure::DrawLabels(IplImage *output, int posx, int posy)
{

	CvFont font;
	cvInitFont(&font,CV_FONT_HERSHEY_PLAIN,0.55,1.0, 0,1,CV_AA);

	// character size
	int chw = 6, chh = 8;

	for (vector<Series>::iterator iter = plots.begin();
		iter != plots.end();
		iter++)
	{
		string lbl = iter->label;
		// draw label if one is available
		if (lbl.length() > 0)
		{
			cvLine(output, cvPoint(posx, posy - chh / 2), cvPoint(posx + 15, posy - chh / 2),
				   iter->color, 2, CV_AA);

			cvPutText(output, lbl.c_str(), cvPoint(posx + 20, posy),
					  &font, iter->color);

			posy += int(chh * 1.5);
		}
	}

}
Пример #23
0
IplImage * BouyBaseObject::TemplateMask(const IplImage * imgIn, const IplImage * threshold, const IplImage * tmplt) const
{
    IplImage * imgOut = cvCloneImage(imgIn);
    //cvZero(imgOut);
    std::list<CvBox2D> blobList;
    blobList  = Zebulon::Vision::VisionUtils::GetBlobBoxes(threshold,.005,.95);
    IplImage * crop;
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1,1);

    for(std::list<CvBox2D>::iterator it = blobList.begin(); it != blobList.end(); it++)
    {

        crop = Zebulon::Vision::VisionUtils::Crop(imgIn,*it);
        double score = 0;
        Zebulon::Vision::VisionUtils::GetSimpleTemplateSimilarity(crop,tmplt,score,false);
        std::ostringstream s;
        s << "(" << score << ")";
        cvPutText(imgOut,s.str().c_str(),cvPointFrom32f(it->center),&font,CV_RGB(255,255,255));
        Zebulon::Vision::VisionUtils::DrawSquare(imgOut,*it);
        if(score > mTemplateThreshold)
        {
            cvDrawCircle(imgOut,cvPointFrom32f(it->center),(crop->width/2.0),CV_RGB(255,255,255));
        }
        cvReleaseImage(&crop);
    }
    return imgOut;
}
Пример #24
0
void nuiVideoFileSource::update()
{
	this->output->lock();

	this->output->clear();

	frame = cvQueryFrame(cap);
	if(frame == NULL) {
		cvReleaseCapture(&cap);
		cvReleaseImage(&frame);
		cap = cvCaptureFromAVI(this->property("path").asString().c_str());
		frame = cvQueryFrame(cap);
	}
	CvFont font;
    double hScale=0.5;
    double vScale=0.5;
    int    lineWidth=1;
    cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale,vScale,0,lineWidth);
	std::ostringstream oss;
	oss << "~ " << this->timer->getAverageFPS() << " FPS";
	cvRectangle(frame, cvPoint(150,0), cvPoint(300,20), cvScalar(0,0,0), CV_FILLED, CV_AA);
	cvRectangle(frame, cvPoint(150,0), cvPoint(300,20), cvScalar(255,100,100), 2, CV_AA);
	cvPutText (frame, oss.str().c_str(), cvPoint(155,15), &font, cvScalar(255,255,255));


	this->outputDataPacket->packData((void*)frame);
	this->output->setData(this->outputDataPacket);
	this->output->transmitData();
	this->output->unlock();
};
Пример #25
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));
}
Пример #26
0
/* chain function
 * this function does the actual processing
 */
static GstFlowReturn
gst_opencv_text_overlay_chain (GstPad * pad, GstObject * parent,
    GstBuffer * buf)
{
  GstOpencvTextOverlay *filter;
  GstMapInfo map_info;
  guint8 *data;

  filter = GST_OPENCV_TEXT_OVERLAY (parent);

  gst_buffer_map (buf, &map_info, GST_MAP_READ);
  data = map_info.data;

  filter->cvImage->imageData = (char *) data;

  cvInitFont (&(filter->font), CV_FONT_VECTOR0, filter->width, filter->height,
      0, filter->thickness, 0);

  buf = gst_buffer_make_writable (buf);
  cvPutText (filter->cvImage, filter->textbuf, cvPoint (filter->xpos,
          filter->ypos), &(filter->font), cvScalar (filter->colorR,
          filter->colorG, filter->colorB, 0));

  gst_buffer_unmap (buf, &map_info);
  return gst_pad_push (filter->srcpad, buf);
}
Пример #27
0
int main(int argc, char* argv[])
{
        // получаем любую подключённую камеру
        CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); //cvCaptureFromCAM( 0 );
        assert( capture );

        //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);//1280); 
        //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);//960); 

        // узнаем ширину и высоту кадра
        double width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
        double height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
        printf("[i] %.0f x %.0f\n", width, height );

        IplImage* frame=0;

        cvNamedWindow("capture", CV_WINDOW_AUTOSIZE);

        printf("[i] press Enter for capture image and Esc for quit!\n\n");

        int counter=0;
        char filename[512];

        char text_buf[32];
        CvFont myFont;
//        cvInitFont(&myFont, СV_FONT_HERSHEY_PLAIN, 0.7, 1, 0, 1, 8);
        cvInitFont(&myFont, CV_FONT_HERSHEY_PLAIN, 2, 1, 0, 1, 8);

        while(true){
                // получаем кадр
                frame = cvQueryFrame( capture );

                //Filters
                cvtColor(frame, pic, CV_BGR2HSV);
                GaussianBlur(pic, pic, Size(7,7), 1.5, 1.5);

                sprintf(text_buf,"Hello!!!");
                cvPutText(frame, text_buf, cvPoint(5,15), &myFont, cvScalar(0,0,255));

                // показываем
                cvShowImage("capture", frame);
        
                char c = cvWaitKey(33);
                if (c == 27) { // нажата ESC
                        break;
                }
                else if(c == 13) { // Enter
                        // сохраняем кадр в файл
                        sprintf(filename, "Image%d.jpg", counter);
                        printf("[i] capture... %s\n", filename);
                        cvSaveImage(filename, frame);
                        counter++;
                }
        }
        // освобождаем ресурсы
        cvReleaseCapture( &capture );
        cvDestroyWindow("capture");
        return 0;
}
static void slPutMaxValue(IplImage *img, sl_int32 max_value)
{
	CvFont font;
	char text[256];
	cvInitFont(&font,CV_FONT_HERSHEY_DUPLEX ,0.5f,0.5f,0,1,CV_AA);
	sprintf(text, "%d", max_value);
	cvPutText(img, text, cvPoint(SL_HIS_START_X / 2, SL_HIS_HEIGHT - SL_HIS_START_Y / 2), &font, CV_RGB(255, 255, 255));
}
Пример #29
0
void TextAdder::addLine(cv::Mat& img, const unsigned int lineNo, const std::string& txt) const
{
  IplImage        tmp = img;
  const size_t    w   = img.size().width - wSpace_;
  const size_t    h   = hSpace_ + lineNo*((fontHeight_*150)/100);
  const cv::Point p(w, h);
  cvPutText( &tmp, txt.c_str(), p, &font_, color_ );
}
Пример #30
0
int main(int argc, char **argv) {
    cvNamedWindow("My Window", 1);
    IplImage *img = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
    CvFont font;
    double hScale = 1.0;
    double vScale = 1.0;
    int lineWidth = 1;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
            hScale, vScale, 0, lineWidth);
    cvPutText(img, "Hello World!, I can now code openCV ", cvPoint(0, 200), &font,
            cvScalar(255, 255, 0));
    cvPutText(img, "in a kickass IDE ", cvPoint(150, 300), &font,
            cvScalar(255, 255, 0));
    cvShowImage("My Window", img);
    cvWaitKey();
    return 0;
}