中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

html5門戶網(wǎng)站模板百度人工客服電話多少

html5門戶網(wǎng)站模板,百度人工客服電話多少,java 構(gòu)建大型網(wǎng)站,國(guó)家信用企業(yè)信息系統(tǒng)OpenCV版本:4.4 IDE:VS2019 功能描述 OpenCV繪制文本的函數(shù)putText()不支持中文的顯示,網(wǎng)上很多方法推薦的都是使用FreeType來支持,FreeType是什么呢?FreeType的官網(wǎng)上有介紹 FreeType官網(wǎng) https://www.freetype.or…

OpenCV版本:4.4
IDE:VS2019

功能描述

OpenCV繪制文本的函數(shù)putText()不支持中文的顯示,網(wǎng)上很多方法推薦的都是使用FreeType來支持,FreeType是什么呢?FreeType的官網(wǎng)上有介紹

FreeType官網(wǎng)

https://www.freetype.org/index.html

網(wǎng)站上都是英文的介紹,閑著沒事,翻譯了一下其介紹,水平有限,湊活著看,如下:

FreeType是一款免費(fèi)的用來渲染字體的軟件庫。

他是用c語言編寫的,體量小,效率高,可高度定制,同時(shí)能夠產(chǎn)生大多數(shù)矢量和位圖字體格式的高質(zhì)量輸出(字形圖像)。

選擇一個(gè)版本進(jìn)行下載,其下載地址如下:

https://sourceforge.net/projects/freetype/files/freetype2/2.10.1/freetype-2.10.1.tar.xz/download

解壓后如下圖所示:

?

配置FreeType

?FreeType文件夾里自帶了vs的工程,在freetype-2.10.4\builds\windows\vc2010\目錄下,直接用vs2019打開freetype.sln,就可以編譯,選擇x64編譯,編譯成功后在freetype-2.10.4\objs\x64\Debug文件夾下面,生成freetype.dll和freetype.lib,如下圖:

新建一個(gè)工程,工程中配置相關(guān)的庫路徑和包含路徑,如下圖所示添加庫的過程。

? 點(diǎn)擊下拉列表,如下圖所示:

點(diǎn)擊編輯,打開添加庫的窗口,如下圖:

把freetype.lib添加進(jìn)去,點(diǎn)擊確定后完成。

然后添加庫的路徑,步驟如下圖:

單擊下拉列表,如下圖:

添加上庫的路徑,單擊確定,完成。

添加包含頭文件的目錄。如下圖:

單擊下拉列表,打開添加包含路徑的窗口,如下圖:

添加路徑后,單擊確定,成功。

添加FreeType的封裝類文件

CvxText.h

#ifndef OPENCV_CVX_TEXT_HPP_
#define OPENCV_CVX_TEXT_HPP_// 支持OpenCV中文漢字輸入#include <ft2build.h>
#include FT_FREETYPE_H#include <opencv2/opencv.hpp>class CvxText {
public:/*** 裝載字庫文件*/CvxText(const char* freeType);virtual ~CvxText();/*** 獲取字體.目前有些參數(shù)尚不支持.** \param font        字體類型, 目前不支持* \param size        字體大小/空白比例/間隔比例/旋轉(zhuǎn)角度* \param underline   下畫線* \param diaphaneity 透明度** \sa setFont, restoreFont*/void getFont(int* type, cv::Scalar* size = nullptr, bool* underline = nullptr, float* diaphaneity = nullptr);/*** 設(shè)置字體.目前有些參數(shù)尚不支持.** \param font        字體類型, 目前不支持* \param size        字體大小/空白比例/間隔比例/旋轉(zhuǎn)角度* \param underline   下畫線* \param diaphaneity 透明度** \sa getFont, restoreFont*/void setFont(int* type, cv::Scalar* size = nullptr, bool* underline = nullptr, float* diaphaneity = nullptr);/*** 恢復(fù)原始的字體設(shè)置.** \sa getFont, setFont*/void restoreFont();/*** 輸出漢字(顏色默認(rèn)為黑色).遇到不能輸出的字符將停止.** \param img  輸出的影象* \param text 文本內(nèi)容* \param pos  文本位置** \return 返回成功輸出的字符長(zhǎng)度,失敗返回-1.*/int putText(cv::Mat& img, const char* text, cv::Point pos);/*** 輸出漢字(顏色默認(rèn)為黑色).遇到不能輸出的字符將停止.** \param img  輸出的影象* \param text 文本內(nèi)容* \param pos  文本位置** \return 返回成功輸出的字符長(zhǎng)度,失敗返回-1.*/int putText(cv::Mat& img, const wchar_t* text, cv::Point pos);/*** 輸出漢字.遇到不能輸出的字符將停止.** \param img   輸出的影象* \param text  文本內(nèi)容* \param pos   文本位置* \param color 文本顏色** \return 返回成功輸出的字符長(zhǎng)度,失敗返回-1.*/int putText(cv::Mat& img, const char* text, cv::Point pos, cv::Scalar color);/*** 輸出漢字.遇到不能輸出的字符將停止.** \param img   輸出的影象* \param text  文本內(nèi)容* \param pos   文本位置* \param color 文本顏色** \return 返回成功輸出的字符長(zhǎng)度,失敗返回-1.*/int putText(cv::Mat& img, const wchar_t* text, cv::Point pos, cv::Scalar color);private:// 禁止copyCvxText& operator=(const CvxText&);// 輸出當(dāng)前字符, 更新m_pos位置void putWChar(cv::Mat& img, wchar_t wc, cv::Point& pos, cv::Scalar color);FT_Library   m_library;   // 字庫FT_Face      m_face;      // 字體// 默認(rèn)的字體輸出參數(shù)int         m_fontType;cv::Scalar   m_fontSize;bool      m_fontUnderline;float      m_fontDiaphaneity;
};#endif // OPENCV_CVX_TEXT_HPP_

CvxText.cpp

#include <wchar.h>
#include <assert.h>
#include <locale.h>
#include <ctype.h>
#include <cmath>
#include "CvxText.h"// 打開字庫
CvxText::CvxText(const char* freeType)
{//INFO("font lib path:%s", freeType);assert(freeType != NULL);// 打開字庫文件, 創(chuàng)建一個(gè)字體FT_Error error;error = FT_Init_FreeType(&m_library);if (error){//INFOE("an error occurred during library initialization");//fprintf(stderr, "an error occurred during library initialization\n");}//if(FT_Init_FreeType(&m_library)) throw;if (FT_New_Face(m_library, freeType, 0, &m_face)) throw;// 設(shè)置字體輸出參數(shù)restoreFont();// 設(shè)置C語言的字符集環(huán)境setlocale(LC_ALL, "");
}// 釋放FreeType資源
CvxText::~CvxText()
{FT_Done_Face(m_face);FT_Done_FreeType(m_library);
}// 設(shè)置字體參數(shù):
//
// font         - 字體類型, 目前不支持
// size         - 字體大小/空白比例/間隔比例/旋轉(zhuǎn)角度
// underline   - 下畫線
// diaphaneity   - 透明度
void CvxText::getFont(int* type, cv::Scalar* size, bool* underline, float* diaphaneity)
{if (type) *type = m_fontType;if (size) *size = m_fontSize;if (underline) *underline = m_fontUnderline;if (diaphaneity) *diaphaneity = m_fontDiaphaneity;
}void CvxText::setFont(int* type, cv::Scalar* size, bool* underline, float* diaphaneity)
{// 參數(shù)合法性檢查if (type) {if (type >= 0) m_fontType = *type;}if (size) {m_fontSize.val[0] = std::fabs(size->val[0]);m_fontSize.val[1] = std::fabs(size->val[1]);m_fontSize.val[2] = std::fabs(size->val[2]);m_fontSize.val[3] = std::fabs(size->val[3]);}if (underline) {m_fontUnderline = *underline;}if (diaphaneity) {m_fontDiaphaneity = *diaphaneity;}FT_Set_Pixel_Sizes(m_face, (int)m_fontSize.val[0], 0);
}// 恢復(fù)原始的字體設(shè)置
void CvxText::restoreFont()
{m_fontType = 0;            // 字體類型(不支持)m_fontSize.val[0] = 80;      // 字體大小m_fontSize.val[1] = 0.5;   // 空白字符大小比例m_fontSize.val[2] = 0.1;   // 間隔大小比例m_fontSize.val[3] = 0;      // 旋轉(zhuǎn)角度(不支持)m_fontUnderline = false;   // 下畫線(不支持)m_fontDiaphaneity = 1.0;   // 色彩比例(可產(chǎn)生透明效果)// 設(shè)置字符大小FT_Set_Pixel_Sizes(m_face, (int)m_fontSize.val[0], 0);
}// 輸出函數(shù)(顏色默認(rèn)為白色)
int CvxText::putText(cv::Mat& img, const char* text, cv::Point pos)
{return putText(img, text, pos, CV_RGB(255, 255, 255));
}int CvxText::putText(cv::Mat& img, const wchar_t* text, cv::Point pos)
{return putText(img, text, pos, CV_RGB(255, 255, 255));
}int CvxText::putText(cv::Mat& img, const char* text, cv::Point pos, cv::Scalar color)
{if (img.data == nullptr) return -1;if (text == nullptr) return -1;int i;for (i = 0; text[i] != '\0'; ++i) {wchar_t wc = text[i];// 解析雙字節(jié)符號(hào)if (!isascii(wc)) mbtowc(&wc, &text[i++], 2);// 輸出當(dāng)前的字符putWChar(img, wc, pos, color);}return i;
}int CvxText::putText(cv::Mat& img, const wchar_t* text, cv::Point pos, cv::Scalar color)
{if (img.data == nullptr) return -1;if (text == nullptr) return -1;int i;for (i = 0; text[i] != '\0'; ++i) {// 輸出當(dāng)前的字符putWChar(img, text[i], pos, color);}return i;
}// 輸出當(dāng)前字符, 更新m_pos位置
void CvxText::putWChar(cv::Mat& img, wchar_t wc, cv::Point& pos, cv::Scalar color)
{// 根據(jù)unicode生成字體的二值位圖FT_UInt glyph_index = FT_Get_Char_Index(m_face, wc);FT_Load_Glyph(m_face, glyph_index, FT_LOAD_DEFAULT);FT_Render_Glyph(m_face->glyph, FT_RENDER_MODE_MONO);FT_GlyphSlot slot = m_face->glyph;// 行列數(shù)int rows = slot->bitmap.rows;int cols = slot->bitmap.width;for (int i = 0; i < rows; ++i) {for (int j = 0; j < cols; ++j) {int off = i * slot->bitmap.pitch + j / 8;if (slot->bitmap.buffer[off] & (0xC0 >> (j % 8))) {int r = pos.y - (rows - 1 - i);int c = pos.x + j;if (r >= 0 && r < img.rows && c >= 0 && c < img.cols) {cv::Vec3b pixel = img.at<cv::Vec3b>(cv::Point(c, r));cv::Scalar scalar = cv::Scalar(pixel.val[0], pixel.val[1], pixel.val[2]);// 進(jìn)行色彩融合float p = m_fontDiaphaneity;for (int k = 0; k < 4; ++k) {scalar.val[k] = scalar.val[k] * (1 - p) + color.val[k] * p;}img.at<cv::Vec3b>(cv::Point(c, r))[0] = (unsigned char)(scalar.val[0]);img.at<cv::Vec3b>(cv::Point(c, r))[1] = (unsigned char)(scalar.val[1]);img.at<cv::Vec3b>(cv::Point(c, r))[2] = (unsigned char)(scalar.val[2]);}}}}// 修改下一個(gè)字的輸出位置double space = m_fontSize.val[0] * m_fontSize.val[1];double sep = m_fontSize.val[0] * m_fontSize.val[2];pos.x += (int)((cols ? cols : space) + sep);
}

源碼

#include <iostream>
#include <opencv2/opencv.hpp>
#include "CvxText.h"int main()
{cv::Mat image = cv::imread("D:\\OpenCVtest\\images\\juice.png");std::string text = "我是果汁";int font_face = cv::FONT_HERSHEY_COMPLEX;double font_scale = 3;int thickness = 8;int baseline;//獲取文本框的長(zhǎng)寬cv::Size text_size = cv::getTextSize(text, font_face, font_scale, thickness, &baseline);//將文本框居中繪制cv::Point origin;origin.x = image.cols / 2 - text_size.width / 2;origin.y = image.rows / 2 + text_size.height / 2;CvxText chinese("D:\\OpenCVtest\\PutTextChinese\\SimHei.ttf");chinese.putText(image, text.c_str(), origin, cv::Scalar(255, 0, 0));imshow("文本繪制", image);cv::waitKey(0);return 0;
}

運(yùn)行結(jié)果

http://www.risenshineclean.com/news/29128.html

相關(guān)文章:

  • 鄭州做網(wǎng)站九零后排名點(diǎn)擊工具
  • 網(wǎng)站開發(fā)程序員 工資百度云怎么找資源
  • 貴陽網(wǎng)站建設(shè)多少錢?影視后期培訓(xùn)機(jī)構(gòu)全國(guó)排名
  • 如何搭建公司網(wǎng)站上海公關(guān)公司
  • 做美圖 網(wǎng)站有哪些付費(fèi)惡意點(diǎn)擊軟件
  • 做局域網(wǎng)網(wǎng)站教程?hào)|莞網(wǎng)絡(luò)優(yōu)化調(diào)查公司
  • 慈溪企業(yè)排名網(wǎng)站培訓(xùn)機(jī)構(gòu)排名全國(guó)十大教育機(jī)構(gòu)排名
  • 做腳本網(wǎng)站建站公司最新報(bào)價(jià)
  • 網(wǎng)站海外推廣哪家好怎么在百度上發(fā)表文章
  • 怎樣做已有網(wǎng)站的編輯維護(hù)四川聚順成網(wǎng)絡(luò)科技有限公司
  • wordpress自建站哪里換logo騰訊企點(diǎn)客服
  • 印度做網(wǎng)站設(shè)計(jì)百度權(quán)重提升
  • 快速收錄網(wǎng)站微信公眾號(hào)運(yùn)營(yíng)
  • 云谷 網(wǎng)站建設(shè)網(wǎng)絡(luò)推廣的方法有
  • 精美化妝品網(wǎng)站模板推廣平臺(tái)排名前十名
  • 專業(yè)微網(wǎng)站建設(shè)公司首選公司哪家好網(wǎng)站排名軟件
  • 黨員寫試卷需要在哪個(gè)網(wǎng)站做輿情管理
  • 建網(wǎng)站學(xué)什么谷歌搜索引擎香港免費(fèi)入口
  • 注冊(cè)網(wǎng)站到公安機(jī)關(guān)備案由誰告知seo關(guān)鍵詞排名優(yōu)化要多少錢
  • 百度seo優(yōu)化技巧東莞seo推廣公司
  • 網(wǎng)站子站建設(shè)aso關(guān)鍵詞優(yōu)化計(jì)劃
  • 動(dòng)態(tài)網(wǎng)站開發(fā)案例教程百度網(wǎng)盤登陸入口
  • 搭建獨(dú)立站專業(yè)軟文代寫
  • 網(wǎng)站推廣每天必做的流程中視頻自媒體賬號(hào)注冊(cè)下載
  • 后海做網(wǎng)站公司網(wǎng)站推廣的渠道有
  • 在國(guó)外怎么做網(wǎng)站服務(wù)營(yíng)銷
  • 做時(shí)時(shí)彩網(wǎng)站被抓廣州新塘網(wǎng)站seo優(yōu)化
  • 文創(chuàng)產(chǎn)品設(shè)計(jì)方案范本優(yōu)化關(guān)鍵詞排名推廣
  • 江蘇省政府門戶網(wǎng)站建設(shè)html+css網(wǎng)頁制作成品
  • 酒業(yè)公司網(wǎng)站模板鄭州百度推廣公司