日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opencv拖动进度条_OpenCV GUI基本操作,回调函数,进度条,裁剪图像等-阿里云开发者社区...

發布時間:2025/3/8 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv拖动进度条_OpenCV GUI基本操作,回调函数,进度条,裁剪图像等-阿里云开发者社区... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

代碼為轉載,出處找不到了,不貼了

工具條進度條:

// ConvertColor.cpp : 定義控制臺應用程序的入口點。

//

#include "stdafx.h"

#include

#include

#include

#pragma comment(lib,"opencv_core2410d.lib")

#pragma comment(lib,"opencv_highgui2410d.lib")

#pragma comment(lib,"opencv_imgproc2410d.lib")

using namespace std;

using namespace cv;

// Global variables

const int slider_max = 100;

int slider;

Mat img;

// Callback function for trackbar event

void on_trackbar(int pos, void *)

{

Mat img_converted;

if(pos > 0) cvtColor(img, img_converted, CV_RGB2GRAY);

else img_converted = img;

imshow("Trackbar app", img_converted);

}

int main()

{

img = imread("swan.jpg");

namedWindow("Trackbar app");

imshow("Trackbar app", img);

slider = 0;

createTrackbar("RGB Grayscale", "Trackbar app", &slider, slider_max, on_trackbar);

while(char(waitKey(1)) != 'q') {}

return 0;

}

效果:

圖像裁切代碼:

// ConvertColor.cpp : 定義控制臺應用程序的入口點。

//

#include "stdafx.h"

#include

#include

#include

#pragma comment(lib,"opencv_core2410d.lib")

#pragma comment(lib,"opencv_highgui2410d.lib")

#pragma comment(lib,"opencv_imgproc2410d.lib")

using namespace std;

using namespace cv;

// Global variables

// Flags updated according to left mouse button activity

bool ldown = false, lup = false;

// Original image

Mat img;

// Starting and ending points of the user's selection

Point corner1, corner2;

// ROI

Rect box;

// Callback function for mouse events

static void mouse_callback(int event, int x, int y, int, void *)

{

// When the left mouse button is pressed, record its position and save it in corner1

if(event == EVENT_LBUTTONDOWN)

{

ldown = true;

corner1.x = x;

corner1.y = y;

cout << "Corner 1 recorded at " << corner1 << endl;

}

// When the left mouse button is released, record its position and save it in corner2

if(event == EVENT_LBUTTONUP)

{

// Also check if user selection is bigger than 20 pixels (jut for fun!)

if(abs(x - corner1.x) > 20 && abs(y - corner1.y) > 20)

{

lup = true;

corner2.x = x;

corner2.y = y;

cout << "Corner 2 recorded at " << corner2 << endl << endl;

}

else

{

cout << "Please select a bigger region" << endl;

ldown = false;

}

}

// Update the box showing the selected region as the user drags the mouse

if(ldown == true && lup == false)

{

Point pt;

pt.x = x;

pt.y = y;

Mat local_img = img.clone();

rectangle(local_img, corner1, pt, Scalar(0, 0, 255));

imshow("Cropping app", local_img);

}

// Define ROI and crop it out when both corners have been selected

if(ldown == true && lup == true)

{

box.width = abs(corner1.x - corner2.x);

box.height = abs(corner1.y - corner2.y);

box.x = min(corner1.x, corner2.x);

box.y = min(corner1.y, corner2.y);

// Make an image out of just the selected ROI and display it in a new window

Mat crop(img, box);

namedWindow("Crop");

imshow("Crop", crop);

ldown = false;

lup = false;

}

}

int main()

{

img = imread("swan.jpg");

namedWindow("Cropping app");

imshow("Cropping app", img);

// Set the mouse event callback function

setMouseCallback("Cropping app", mouse_callback);

// Exit by pressing 'q'

while(char(waitKey(1)) != 'q') {}

return 0;

}

裁切效果:

總結

以上是生活随笔為你收集整理的opencv拖动进度条_OpenCV GUI基本操作,回调函数,进度条,裁剪图像等-阿里云开发者社区...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。