Ask Your Question
0

Question mark behind local time

asked 2013-08-31 12:41:21 -0500

OCV gravatar image

updated 2013-08-31 16:28:47 -0500

I want to display the system time in windows and recorde a video but I dont know why there is a question mark behind the year part of the time. Anybody know why?

Code that I am using:

#include <C:\Users\AM\Desktop\Project\opencv\build\include\opencv2\objdetect\objdetect.hpp>
#include <C:\Users\AM\Desktop\Project\opencv\build\include\opencv2\highgui\highgui.hpp>
#include <C:\Users\AM\Desktop\Project\opencv\build\include\opencv2\imgproc\imgproc.hpp>
#include <C:\Users\AM\Desktop\Project\opencv\build\include\opencv\cv.h>
#include <C:\Users\AM\Desktop\Project\opencv\build\include\opencv2\core\core.hpp>
#include <C:\Users\AM\Desktop\Project\opencv\build\include\opencv2\videostab\optical_flow.hpp>
#include <C:\Users\AM\Desktop\Project\opencv\build\include\opencv2\videostab\videostab.hpp>

#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;
using namespace cv;

int numFaces;
int numEyes;

 /** Function Headers */
 void detectAndDisplay( Mat frame );
 void videoRecord (Mat frame);

 /** Global variables */
 String face_cascade_name = "haarcascade_frontalface_alt.xml";
 String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";

 CascadeClassifier face_cascade;
 CascadeClassifier eyes_cascade;
 string window_name = "Capture - Face detection";
 RNG rng(12345);

 VideoCapture capture;
 VideoWriter record;

 time_t now;

 /** @function main */
 int main( int argc, const char** argv )
 {

  Mat frame;

      //-- 1. Load the cascades
   if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
   if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

   //-- 2. Read the video stream
   capture.open(0);// = cvCaptureFromCAM( -1 );

   if( capture.isOpened() )
   {
    int width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
    int height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);

    capture >> frame;

    record.open("C:/Users/AM/Google Drive/Intruder.avi", CV_FOURCC('D','I','V','X'), 9, cvSize(width, height), true);

     while( true )
     {
       //frame = cvQueryFrame( capture );
       capture >> frame;

   //-- 3. Apply the classifier to the frame
       if( !frame.empty() )
       { 
           detectAndDisplay( frame ); 
          if (numEyes == 2)
           {
            videoRecord(frame);
            //numEyes = 0;
           }
       }
       else
       { printf(" --(!) No captured frame -- Break!"); break; }

         //pause for 33ms        
         if (waitKey(33) == 27) 
         break; 
       }
   } 
   return 0;
 }

/** @function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
  std::vector<Rect> faces;
  Mat frame_gray;

  //time (&rawtime);
  //timeinfo = localtime (&rawtime);
  string str;
  now = time(NULL);
  str = ctime(&now);


  cvtColor( frame, frame_gray, CV_BGR2GRAY );
  equalizeHist( frame_gray, frame_gray );

  //-- Detect faces
  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

  putText(frame, str, cvPoint(5, 25), CV_FONT_HERSHEY_SIMPLEX, 0.5, CV_RGB(0, 0, 255), 2, 8, FALSE);


  for( int i = 0; i < faces.size(); i++ )
  {
  //draw face
    Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
    ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

    //get region of interest
    Mat faceROI = frame_gray( faces[i] );
    std::vector<Rect> eyes;

    //-- In each face, detect eyes
    eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );

    for( int j = 0; j < eyes.size(); j++ )
     {
     //draw eyes
       Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
       int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
       circle( frame, center, radius, Scalar ...
(more)
edit retag flag offensive close merge delete

Comments

2

I suppose we need more code to answer your question.

SR gravatar imageSR ( 2013-08-31 13:24:54 -0500 )edit

1 answer

Sort by » oldest newest most voted
3

answered 2013-08-31 13:54:48 -0500

berak gravatar image

updated 2013-08-31 17:36:02 -0500

dear OCV, if you look at the docs for ctime, you'll see that the date string ends with "\n".

putText can't show newlines, and thus prints a '?' for anything it does not know.

there's 2 things you can do about it:

° take out the axe, and chop off the last char:

time_t now;
time(&now);
char * ct = ctime(&now);
int l = strlen(ct);
ct[l-1] = 0;
putText(im,ct, ...

° use strftime instead, and format your own date.

actually i'd recommend the latter, as you got more control on the outcome here (what country are you in ? you'd want to format your date according to that)

(as a side note, next time please try to cut it down to a minimal testcase (all your face detection code has got nothing to do with the problem. also, if you post code, please use the 10101 button to format it properly)

edit flag offensive delete link more

Comments

1

+1 for being so patient.

SR gravatar imageSR ( 2013-08-31 14:41:04 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-08-31 12:41:21 -0500

Seen: 374 times

Last updated: Aug 31 '13