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

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

網(wǎng)站怎么做移動端免費(fèi)推廣神器

網(wǎng)站怎么做移動端,免費(fèi)推廣神器,建設(shè)網(wǎng)站專業(yè)公司,做網(wǎng)站的公司地址ubuntu22.04laptop OpenCV Get Started: 012_mouse_and_trackbar 1. 源由2. mouse/trackbar應(yīng)用Demo2.1 C應(yīng)用Demo2.2 Python應(yīng)用Demo 3. 鼠標(biāo)位置跟蹤注釋3.1 注冊回調(diào)函數(shù)3.2 回調(diào)操作3.3 效果 4. 使用軌跡欄調(diào)整圖像大小4.1 初始化軌跡欄&注冊回調(diào)函數(shù)4.2 回調(diào)操作4.3 效…

ubuntu22.04@laptop OpenCV Get Started: 012_mouse_and_trackbar

  • 1. 源由
  • 2. mouse/trackbar應(yīng)用Demo
    • 2.1 C++應(yīng)用Demo
    • 2.2 Python應(yīng)用Demo
  • 3. 鼠標(biāo)位置跟蹤注釋
    • 3.1 注冊回調(diào)函數(shù)
    • 3.2 回調(diào)操作
    • 3.3 效果
  • 4. 使用軌跡欄調(diào)整圖像大小
    • 4.1 初始化軌跡欄&注冊回調(diào)函數(shù)
    • 4.2 回調(diào)操作
    • 4.3 效果
  • 4. 總結(jié)
  • 5. 參考資料
  • 6. 補(bǔ)充

1. 源由

鼠標(biāo)指針和軌跡條是圖形用戶界面(GUI)中的關(guān)鍵組件。

如果沒有這些關(guān)鍵交互組件,就無法真正考慮與GUI交互。

因此,結(jié)合演示代碼了解OpenCV中鼠標(biāo)和軌跡條的內(nèi)置功能,對于程序交互來說至關(guān)重要。

2. mouse/trackbar應(yīng)用Demo

012_mouse_and_trackbar是OpenCV通過鼠標(biāo)指針和軌跡條與用戶交互的示例。

2.1 C++應(yīng)用Demo

C++應(yīng)用Demo工程結(jié)構(gòu):

012_mouse_and_trackbar/CPP$ tree .
.
├── Mouse
│   ├── CMakeLists.txt
│   └── mouse.cpp
└── Trackbar├── CMakeLists.txt└── trackbar.cpp2 directories, 4 files

確認(rèn)OpenCV安裝路徑:

$ find /home/daniel/ -name "OpenCVConfig.cmake"
/home/daniel/OpenCV/installation/opencv-4.9.0/lib/cmake/opencv4/
/home/daniel/OpenCV/opencv/build/OpenCVConfig.cmake
/home/daniel/OpenCV/opencv/build/unix-install/OpenCVConfig.cmake$ export OpenCV_DIR=/home/daniel/OpenCV/installation/opencv-4.9.0/lib/cmake/opencv4/

C++應(yīng)用Demo工程編譯執(zhí)行:

$ cd Mouse
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ cd ..
$ ./build/mouse
$ cd Trackbar
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ cd ..
$ ./build/trackbar

2.2 Python應(yīng)用Demo

Python應(yīng)用Demo工程結(jié)構(gòu):

012_mouse_and_trackbar/Python$ tree .
.
├── requirements.txt
├── mouse.py
└── trackbar.py0 directories, 3 files

Python應(yīng)用Demo工程執(zhí)行:

$ workoncv-4.9.0
$ python mouse.py
$ python trackbar.py

3. 鼠標(biāo)位置跟蹤注釋

3.1 注冊回調(diào)函數(shù)

OpenCV提供了鼠標(biāo)事件檢測功能,用于檢測各種鼠標(biāo)操作。

代碼上采用注冊回調(diào)函數(shù)方式實(shí)現(xiàn):

C++:

// highgui function called when mouse events occur
setMouseCallback("Window", drawRectangle);

Python:

# highgui function called when mouse events occur
cv2.setMouseCallback("Window", drawRectangle)

3.2 回調(diào)操作

當(dāng)有鼠標(biāo)操作時:

  • EVENT_LBUTTONDOWN:記錄左上角坐標(biāo)
  • EVENT_LBUTTONUP:記錄右下角坐標(biāo),并更新圖像

實(shí)現(xiàn)對左上角和右下角的框選,矩形框標(biāo)注選擇范圍。

C++:

// Points to store the center of the circle and a point on the circumference
Point top_left_corner, bottom_right_corner;
// image image
Mat image;// function which will be called on mouse input
void drawRectangle(int action, int x, int y, int flags, void *userdata)
{// Mark the center when left mouse button is pressedif( action == EVENT_LBUTTONDOWN ){top_left_corner = Point(x,y);}// When left mouse button is releasedelse if( action == EVENT_LBUTTONUP){bottom_right_corner = Point(x,y);// Draw rectanglerectangle(image, top_left_corner, bottom_right_corner, Scalar(0,255,0), 2, 8 );// Display imageimshow("Window", image);}}

Python:

# Lists to store the points
top_left_corner=[]
bottom_right_corner=[]# Define drawRectangle function
def drawRectangle(action, x, y, flags, *userdata):# Referencing global variables global top_left_corner, bottom_right_corner# Action to be taken when left mouse button is pressedif action == cv2.EVENT_LBUTTONDOWN:top_left_corner = [(x,y)]# Action to be taken when left mouse button is releasedelif action == cv2.EVENT_LBUTTONUP:bottom_right_corner = [(x,y)]    # Draw the rectanglecv2.rectangle(image, top_left_corner[0], bottom_right_corner[0], (0,255,0),2, 8)cv2.imshow("Window",image)

3.3 效果

在這里插入圖片描述

4. 使用軌跡欄調(diào)整圖像大小

4.1 初始化軌跡欄&注冊回調(diào)函數(shù)

創(chuàng)建軌跡欄對象時,代碼上采用注冊回調(diào)函數(shù)方式實(shí)現(xiàn):

C++:

int maxScaleUp = 100;
int scaleFactor = 1;string windowName = "Resize Image";
string trackbarValue = "Scale";// Create Trackbars and associate a callback function
createTrackbar(trackbarValue, windowName, &scaleFactor, maxScaleUp, scaleImage);

Python:

maxScaleUp = 100
scaleFactor = 1
windowName = "Resize Image"
trackbarValue = "Scale"# Create trackbar
cv2.createTrackbar(trackbarValue, windowName, scaleFactor, maxScaleUp, scaleImage)

4.2 回調(diào)操作

當(dāng)有拖動軌跡欄滑塊時,調(diào)用回調(diào)函數(shù)。根據(jù)滑塊位置,對圖像進(jìn)行比例縮放。

C++:

// Callback functions
void scaleImage(int, void*)
{// Read the imageMat image = imread("../../Input/sample.jpg");// Get the Scale factor from the trackbardouble scaleFactorDouble = 1 + scaleFactor/100.0;// Set the factor to 1 if becomes 0if (scaleFactorDouble == 0){scaleFactorDouble = 1;}Mat scaledImage;// Resize the imageresize(image, scaledImage, Size(), scaleFactorDouble, scaleFactorDouble, INTER_LINEAR);// Display the imageimshow(windowName, scaledImage);
}

Python:

# Callback functions
def scaleImage(*args):# Get the scale factor from the trackbar scaleFactor = 1+ args[0]/100.0# Resize the imagescaledImage = cv2.resize(image, None, fx=scaleFactor, fy = scaleFactor, interpolation = cv2.INTER_LINEAR)cv2.imshow(windowName, scaledImage)

4.3 效果

通過軌跡欄的拖動,實(shí)現(xiàn)圖像的放大縮小。

在這里插入圖片描述在這里插入圖片描述

4. 總結(jié)

本文通過設(shè)置setMouseCallbackcreateTrackbar注冊鼠標(biāo)操作回調(diào)函數(shù)和軌跡欄空間回調(diào)函數(shù),實(shí)現(xiàn)對應(yīng)的OpenCV圖像操作。

  • setMouseCallback(winname, onMouse, userdata)
  • winname Name of the window.
  • onMouse Callback function for mouse events. See OpenCV samples on how to specify and use the callback.
  • userdata The optional parameter passed to the callback.
  • createTrackbar( trackbarName, windowName, value, count, onChange)
  • trackbarname Name of the created trackbar.
  • winname Name of the window that will be used as a parent of the created trackbar.
  • value Optional pointer to an integer variable whose value reflects the position of the slider. Upon creation, the slider position is defined by this variable.
  • count Maximal position of the slider. The minimal position is always 0.
  • onChange Pointer to the function to be called every time the slider changes position. This function should be prototyped as void Foo(int,void*); , where the first parameter is the trackbar position and the second parameter is the user data (see the next parameter). If the callback is the NULL pointer, no callbacks are called, but only value is updated.
  • userdata User data that is passed as is to the callback. It can be used to handle trackbar events without using global variables.

5. 參考資料

【1】ubuntu22.04@laptop OpenCV Get Started
【2】ubuntu22.04@laptop OpenCV安裝
【3】ubuntu22.04@laptop OpenCV定制化安裝

6. 補(bǔ)充

學(xué)習(xí)是一種過程,對于前面章節(jié)學(xué)習(xí)討論過的,就不在文中重復(fù)了。

有興趣了解更多的朋友,請從《ubuntu22.04@laptop OpenCV Get Started》開始,一個章節(jié)一個章節(jié)的了解,循序漸進(jìn)。

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

相關(guān)文章:

  • asp網(wǎng)站建設(shè)實(shí)錄源碼推廣注冊app拿傭金平臺
  • 大氣的網(wǎng)站首頁google搜索引擎入口下載
  • 加強(qiáng)網(wǎng)站政務(wù)服務(wù)建設(shè)永久免費(fèi)域名申請
  • 成都b2c網(wǎng)站服裝營銷方式和手段
  • 酒店網(wǎng)站報價方案廣東網(wǎng)絡(luò)seo推廣公司
  • 獨(dú)立站和企業(yè)網(wǎng)站區(qū)別網(wǎng)絡(luò)技術(shù)培訓(xùn)
  • 個人博客網(wǎng)站制作論文網(wǎng)站關(guān)鍵詞快速排名服務(wù)
  • 軟件企業(yè)網(wǎng)站模板2023全民核酸又開始了
  • 做網(wǎng)站需要多少資金如何建立個人網(wǎng)址
  • 軟件工程畢業(yè)可以做網(wǎng)站嗎購買網(wǎng)站域名
  • 學(xué)做網(wǎng)站要學(xué)什么語言熱狗網(wǎng)站關(guān)鍵詞優(yōu)化
  • 寧波seo網(wǎng)絡(luò)推廣推薦公眾號seo工資水平
  • 子網(wǎng)站怎么建設(shè)產(chǎn)品營銷策略有哪些
  • 旅游網(wǎng)站有哪些功能指數(shù)基金什么意思
  • 手機(jī)賺錢網(wǎng)站新河seo怎么做整站排名
  • iis搭建網(wǎng)站seo學(xué)校培訓(xùn)課程
  • 長沙交互網(wǎng)站設(shè)計服務(wù)商愛站網(wǎng)seo綜合查詢
  • 網(wǎng)站怎么在百度做推廣看今天的新聞
  • 簡單的手機(jī)網(wǎng)站模板下載國內(nèi)企業(yè)網(wǎng)站模板
  • 網(wǎng)頁美工設(shè)計課程谷歌優(yōu)化師
  • 網(wǎng)站500m空間夠用嗎seo快速排名源碼
  • 手機(jī)設(shè)計端點(diǎn)seo博客
  • 網(wǎng)站設(shè)計班培訓(xùn)北京seo網(wǎng)絡(luò)優(yōu)化招聘網(wǎng)
  • 聯(lián)通公司網(wǎng)站誰做的網(wǎng)絡(luò)營銷的推廣方法有哪些
  • 網(wǎng)站建設(shè)費(fèi)計入什么科目代運(yùn)營公司排行榜
  • 設(shè)計網(wǎng)站私單價格草根seo博客
  • 網(wǎng)站社區(qū)的建設(shè)外鏈生成
  • 商城網(wǎng)站建設(shè)好么百度貼吧怎么做推廣
  • 和一起做網(wǎng)店類似的網(wǎng)站18歲以上站長統(tǒng)計
  • 論壇網(wǎng)站建設(shè)流程長沙網(wǎng)站推廣工具