Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How can I display timer results with a C++ "putText" command?

I working on several Android OpenCV samples, which use native C++ code to perform operations. I have implemented a timer in the C++ code and I would like to display the results of the timer. I have checked a putText command and it works great but I don' t know how to show the results of the timer with it. Here is the code of native part of the application:

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;

extern "C" {
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3View_FindFeatures(JNIEnv* env, 
jobject, jint width, jint height, jbyteArray yuv, jintArray bgra)  
{
jbyte* _yuv  = env->GetByteArrayElements(yuv, 0);
jint*  _bgra = env->GetIntArrayElements(bgra, 0);

Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra);
Mat mgray(height, width, CV_8UC1, (unsigned char *)_yuv);

//Please make attention about BGRA byte order
//ARGB stored in java as int array becomes BGRA at native level
cvtColor(myuv, mbgra, CV_YUV420sp2BGR, 4);

vector<KeyPoint> v;

OrbFeatureDetector  detector(1);
double t = (double)getTickCount();
detector.detect(mgray, v);
t = ((double)getTickCount() - t)/getTickFrequency();
putText(mbgra, t+ " detection time", Point2f(100,100), FONT_HERSHEY_PLAIN, 2,  Scalar(0,0,255,255), 2);
for( size_t i = 0; i < v.size(); i++ )
    circle(mbgra, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255));
env->ReleaseIntArrayElements(bgra, _bgra, 0);
env->ReleaseByteArrayElements(yuv, _yuv, 0);
}
}

When I compile everything in Eclipse, I get an error: "invalid operands of types 'double' and 'char const [15]' to binary 'operator+'". What am I doing wrong? Is it possible to display the timer results with a "putText" command? How else can I display the measure results?

How can I display timer results with a C++ "putText" command?

I working on several Android OpenCV samples, which use native C++ code to perform operations. I have implemented a timer in the C++ code and I would like to display the results of the timer. I have checked a putText command and it works great but I don' t know how to show the results of the timer with it. Here is the code of native part of the application:

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;

extern "C" {
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3View_FindFeatures(JNIEnv* env, 
jobject, jint width, jint height, jbyteArray yuv, jintArray bgra)  
{
jbyte* _yuv  = env->GetByteArrayElements(yuv, 0);
jint*  _bgra = env->GetIntArrayElements(bgra, 0);

Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra);
Mat mgray(height, width, CV_8UC1, (unsigned char *)_yuv);

//Please make attention about BGRA byte order
//ARGB stored in java as int array becomes BGRA at native level
cvtColor(myuv, mbgra, CV_YUV420sp2BGR, 4);

vector<KeyPoint> v;

OrbFeatureDetector  detector(1);
double t = (double)getTickCount();
detector.detect(mgray, v);
t = ((double)getTickCount() - t)/getTickFrequency();
putText(mbgra, t+ " detection time", Point2f(100,100), FONT_HERSHEY_PLAIN, 2,  Scalar(0,0,255,255), 2);
for( size_t i = 0; i < v.size(); i++ )
    circle(mbgra, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255));
env->ReleaseIntArrayElements(bgra, _bgra, 0);
env->ReleaseByteArrayElements(yuv, _yuv, 0);
}
}

When I compile everything in Eclipse, I get an error: "invalid operands of types 'double' and 'char const [15]' to binary 'operator+'". What am I doing wrong? Is it possible to display the timer results with a "putText" command? How else can I display the measure results?

@Mostafa Sataki Your code is much better but now I get an error: "cannot convert 'double' to 'char const' for argument '2' to 'int sprintf(char, char const*, ...)' ". I don't know how to fix it. Something wrong must be in my timer. Can you help me with it?

How can I display timer results with a C++ "putText" command?

I working on several Android OpenCV samples, which use native C++ code to perform operations. I have implemented a timer in the C++ code and I would like to display the results of the timer. I have checked a putText command and it works great but I don' t know how to show the results of the timer with it. Here is the code of native part of the application:

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;

extern "C" {
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3View_FindFeatures(JNIEnv* env, 
jobject, jint width, jint height, jbyteArray yuv, jintArray bgra)  
{
jbyte* _yuv  = env->GetByteArrayElements(yuv, 0);
jint*  _bgra = env->GetIntArrayElements(bgra, 0);

Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv);
Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra);
Mat mgray(height, width, CV_8UC1, (unsigned char *)_yuv);

//Please make attention about BGRA byte order
//ARGB stored in java as int array becomes BGRA at native level
cvtColor(myuv, mbgra, CV_YUV420sp2BGR, 4);

vector<KeyPoint> v;

OrbFeatureDetector  detector(1);
double t = (double)getTickCount();
detector.detect(mgray, v);
t = ((double)getTickCount() - t)/getTickFrequency();
putText(mbgra, t+ " detection time", Point2f(100,100), FONT_HERSHEY_PLAIN, 2,  Scalar(0,0,255,255), 2);
for( size_t i = 0; i < v.size(); i++ )
    circle(mbgra, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255));
env->ReleaseIntArrayElements(bgra, _bgra, 0);
env->ReleaseByteArrayElements(yuv, _yuv, 0);
}
}

When I compile everything in Eclipse, I get an error: "invalid operands of types 'double' and 'char const [15]' to binary 'operator+'". What am I doing wrong? Is it possible to display the timer results with a "putText" command? How else can I display the measure results?

@Mostafa Sataki Your code is much better but now I get an error: "cannot convert 'double' to 'char const' for argument '2' to 'int sprintf(char, char const*, ...)' ". I don't know how to fix it. Something wrong must be wrong in my timer. Can you help me with it?