引用内容:https://blog.csdn.net/wanggao_1990/article/details/52955056
添加头文件putText.h,添加内容:
#pragma once
#define PUTTEXT_H_
#include <windows.h>
#include <string>
#include <opencv2/opencv.hpp>
using namespace cv;
void GetStringSize(HDC hDC, const char* str, int* w, int* h);
void putTextZH(Mat &dst, const char* str, Point2i org, Scalar color, int fontSize,
const char *fn = "Arial", bool italic = false, bool underline = false);
主函数Dlg中添加以下内容:
void GetStringSize(HDC hDC, const char* str, int* w, int* h)
{
SIZE size;
GetTextExtentPoint32A(hDC, str, strlen(str), &size);
if (w != 0) *w = size.cx;
if (h != 0) *h = size.cy;
}
void putTextZH(Mat &dst, const char* str, Point2i org, Scalar color, int fontSize, const char* fn, bool italic, bool underline)
{
CV_Assert(dst.data != 0 && (dst.channels() == 1 || dst.channels() == 3));
int x, y, r, b;
if (org.x > dst.cols || org.y > dst.rows) return;
x = org.x < 0 ? -org.x :