OpenCV GUI基本操作,回调函数,进度条,裁剪图像等
代码为转载,出处找不到了,不贴了
工具条进度条:
// ConvertColor.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> #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 <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> #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 GUI基本操作,回调函数,进度条,裁剪图像等的更多相关文章
- 为OLED屏添加GUI支持6:进度条控件
为OLED屏添加GUI支持6:进度条控件 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN10 开发环境:MDK5.13 MCU:S ...
- iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像
iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像 本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImag ...
- Opencv step by step - 视频进度条
上一个博文只是进行了视频播放,这里加上进度条. 下面是修改好的代码: #include <cv.h> #include <highgui.h> /* * tan@ubuntu: ...
- Video Toolbox:读写解码回调函数CVImageBufferRef的YUV图像
本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImageBufferRef中的YUV或RGB数据的方法,并给出CVImageBufferRef生成灰度图代码.方便调 ...
- OpenCV常用基本处理函数(2)图像基本操作
可以根据像素的行和列的坐标获取他的像素值.对 BGR 图像而言,返回值为 B,G,R 例如获取蓝色的像素值: img=cv2.imread('messi5.jpg')px=img[100,100]bl ...
- OpenCV常用基本处理函数(7)图像金字塔和直方图
高斯金字塔 高斯金字塔的顶部是通过将底部图像中的连续的行和列去除得到的.顶部图像中的每个像素值等于下一层图像中 5 个像素的高斯加权平均值. 这样操作一次一个 MxN 的图像就变成了一个 M/2xN/ ...
- OpenCV常用基本处理函数(6)图像梯度
形态学转换 腐蚀 img = cv2.imread() kernel = np.ones((,),np.uint8) erosion = cv2.erode(img,kernel,iterations ...
- python-----opencv读视频、循环读图片显示进度条
功能:opencv读视频,显示进度条,推动进度条快进.后退,按q退出.代码如下: import os import cv2 def nothing(emp): pass def jindu(name, ...
- 用layer-list实现弧形进度条
本文转载自:http://www.linuxidc.com/Linux/2013-04/82743.htm 之前我有写过如何用style或者是layer-list实现自定义的横向进度条(http:// ...
随机推荐
- 1CCTableView的使用,TableView响应和小格子tableView实现
1 CCTableView的使用 T26TableView.h #ifndef __T26TableView_H__ #define __T26TableView_H__ #includ ...
- Android监听屏幕解锁和判断屏幕状态
开发后台服务的时候经常需要对屏幕状态进行判断,如果是想要监听屏幕解锁事件,可以在配置里面注册action为 android.intent.action.USER_PRESENT的广播,则可以监听解锁事 ...
- Struts 1 之配置文件
web.xml中配置Struts的入口Servlet--ActionServlet,ActionServlet不负责任何的业务处理,它只是查找Action名单,找到path属性与URL属性一致的Act ...
- Android开源框架ViewPagerIndicator的基本使用
转载本博客请注明出处:点击打开链接 http://blog.csdn.net/qq_32059827/article/details/52495647 很多新闻资讯类的app都有一些共性,那就是 ...
- EPnP算法
EPnP算法 相机坐标系用\(F^c\),世界坐标系用\(F^w\)表示,任何一点可以用四个控制点\(p_i^w\)表示 \begin{equation} p_i^w=\sum_{j=1}^4\alp ...
- 编译GDAL支持MySQL
GDAL支持MySQL需要MySQL的库才可以,编译很简单,修改nmake.opt文件中对应的MySQL的库的路径和lib即可. nmake.opt文件中397行左右,如下: # MySQL Libr ...
- springMVC源码分析--国际化LocaleResolver(一)
springMVC给我们提供了国际化支持,简单来说就是设置整个系统的运行语言,然后根据系统的运行语言来展示对应语言的页面,一般我们称之为多语言.springMVC国际化机制就是可以设置整个系统的运行语 ...
- (七十五)CoreLocation(一)在iOS7和iOS8设备上获取授权
苹果在iOS8上更新了CoreLocation的授权获取方式,在原来的基础上,不仅需要调用授权函数,还需要对info.plist进行相应的配置. 在iOS上获取经纬度使用的是CoreLocationM ...
- Java与C之间的socket通信
最近正在开发一个基于指纹的音乐检索应用,算法部分已经完成,所以尝试做一个Android App.Android与服务器通信通常采用HTTP通信方式和Socket通信方式.由于对web服务器编程了解较少 ...
- ListView控件使用
//ListView标头的代码创建方法. ColumnHeader title=new ColumnHeader(); //声明标头,并创建对象. title.Text="标头1名称&quo ...