为什么cv :: format没有给我预期的结果?
我正在发布模式下使用带有VS 2015的C ++的openCV 3.4.0
I am working with openCV 3.4.0 using C++ with VS 2015 in release mode
我正在尝试将文本放在cv :: Mat中的特定位置.
I am trying to put text on a specific place in the cv::Mat.
当我尝试这样做时,它会起作用:
While I am trying this it works:
//int FPS = calculate_FPS(measure_time(false));
int FPS = 6;
std::cout << "FPS = " << FPS << std::endl;
measure_time(true);
cv::putText(canvas(frame_per_second_area), cv::format("FPS: %d", FPS) , cv::Point(frame_per_second_area.width*0.20, frame_per_second_area.height*0.7), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(0, 0, 0));
它看起来像:
直到这里一切都很好. 但是,当我尝试这种方式时,会得到不好的结果:
Until here everything is fine. However while I trying this way I get bad results:
int FPS = calculate_FPS(measure_time(false));
//int FPS = 6;
std::cout << "FPS = " << FPS << std::endl;
measure_time(true);
cv::putText(canvas(frame_per_second_area), cv::format("FPS: %d", FPS) , cv::Point(frame_per_second_area.width*0.20, frame_per_second_area.height*0.7), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(0, 0, 0));
它看起来像:
需要提及的是,屏幕输出看起来不错:
Need to mention that the output to the screen looks good:
需要提及#2-这是函数声明:
Need to mention #2 - This is the function declaration:
int calculate_FPS(double elapsed_time_in_ms);
问题不是在调用:calculate_FPS(measure_time(false));
与否.实际的问题是您在同一画布上重复渲染文本.我可以向您演示一下:
The problem is not calling: calculate_FPS(measure_time(false));
or not. The actual problem is that you rendering the text repeatedly on the same canvas. I can demonstrate this to you:
canvas = np.ones((100, 200, 3), dtype=np.uint8)
# Set the canvas background color as Red.
canvas[:, :] = np.array([0, 0, 255])
for i in xrange(15):
cv2.putText(canvas, "FPS: " + str(i), (50, 70), cv2.FONT_HERSHEY_PLAIN, 1, np.array([0, 0, 0]))
canvas = np.ones((100, 200, 3), dtype=np.uint8)
# Set the canvas background color as Red.
canvas[:, :] = np.array([0, 0, 255])
for i in xrange(15):
canvas[:, :] = np.array([0, 0, 255])
cv2.putText(canvas, "FPS: " + str(i), (50, 70), cv2.FONT_HERSHEY_PLAIN, 1, np.array([0, 0, 0]))