我正在使用C ++和VS 2015在发布模式下使用openCV 3.4.0
我正在尝试将文本放在cv :: Mat中的特定位置。
当我尝试这样做时,它会起作用:
//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));
它看起来像:
直到这里一切都很好。 但是,当我尝试这种方式时,会得到不好的结果:
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));
它看起来像:
需要提及的是,屏幕输出看起来不错:
需要提及#2-这是函数声明:
int calculate_FPS(double elapsed_time_in_ms);
答案 0 :(得分:1)
问题不在于:是否calculate_FPS(measure_time(false));
。实际的问题是您在同一画布上重复渲染文本。我可以向你演示一下
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]))