代码为转载,出处找不到了,不贴了

工具条进度条:

// 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基本操作,回调函数,进度条,裁剪图像等的更多相关文章

  1. 为OLED屏添加GUI支持6:进度条控件

    为OLED屏添加GUI支持6:进度条控件 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN10 开发环境:MDK5.13 MCU:S ...

  2. iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像

    iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像 本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImag ...

  3. Opencv step by step - 视频进度条

    上一个博文只是进行了视频播放,这里加上进度条. 下面是修改好的代码: #include <cv.h> #include <highgui.h> /* * tan@ubuntu: ...

  4. Video Toolbox:读写解码回调函数CVImageBufferRef的YUV图像

    本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImageBufferRef中的YUV或RGB数据的方法,并给出CVImageBufferRef生成灰度图代码.方便调 ...

  5. OpenCV常用基本处理函数(2)图像基本操作

    可以根据像素的行和列的坐标获取他的像素值.对 BGR 图像而言,返回值为 B,G,R 例如获取蓝色的像素值: img=cv2.imread('messi5.jpg')px=img[100,100]bl ...

  6. OpenCV常用基本处理函数(7)图像金字塔和直方图

    高斯金字塔 高斯金字塔的顶部是通过将底部图像中的连续的行和列去除得到的.顶部图像中的每个像素值等于下一层图像中 5 个像素的高斯加权平均值. 这样操作一次一个 MxN 的图像就变成了一个 M/2xN/ ...

  7. OpenCV常用基本处理函数(6)图像梯度

    形态学转换 腐蚀 img = cv2.imread() kernel = np.ones((,),np.uint8) erosion = cv2.erode(img,kernel,iterations ...

  8. python-----opencv读视频、循环读图片显示进度条

    功能:opencv读视频,显示进度条,推动进度条快进.后退,按q退出.代码如下: import os import cv2 def nothing(emp): pass def jindu(name, ...

  9. 用layer-list实现弧形进度条

    本文转载自:http://www.linuxidc.com/Linux/2013-04/82743.htm 之前我有写过如何用style或者是layer-list实现自定义的横向进度条(http:// ...

随机推荐

  1. Windows运行GitStats

    Windows运行GitStats(金庆的专栏)GitStats - git history statistics generatorhttp://gitstats.sourceforge.net/G ...

  2. Apache shiro集群实现 (三)shiro身份认证(Shiro Authentication)

    Apache shiro集群实现 (一) shiro入门介绍 Apache shiro集群实现 (二) shiro 的INI配置 Apache shiro集群实现 (三)shiro身份认证(Shiro ...

  3. [Pelican]Pelican入门(一)

    听说这个静态博客很好用,最近又在协助"蟒周刊"翻译,于是先学习下基本的用法 office site You can startup for here. 安装环境 我的os是win7 ...

  4. Android Multimedia框架总结(八)Stagefright框架之AwesomePlayer及数据解析器

    转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼:http://blog.csdn.net/hejjunlin/article/details/52503057 前言:前面一篇分析了medi ...

  5. springmvc文件上传和拦截器

    文件上传 用到这两个包 配置视图解析器:springmvc配置文件配置 <!-- id必须要是"multipartResolver" --> <bean id=& ...

  6. Hibernate实体映射文件多对多等关系简单应用技巧

    认真开完以后,就能很简单的写出各种关系了 第一步,写注释: <!--xx属性,本类与Yy(类)的多对一 --> <!--xx属性,本类与Yy(类)的一对多 --> <!- ...

  7. 20 ViewPager demo5,6:FragmentAdapter 导航数据

    Demo5 文件结构: MainActivity.java package com.qf.day20_viewpager_demo5; import java.util.ArrayList; impo ...

  8. hive元数据库表分析及操作

    在安装Hive时,需要在hive-site.xml文件中配置元数据相关信息.与传统关系型数据库不同的是,hive表中的数据都是保存的HDFS上,也就是说hive中的数据库.表.分区等都可以在HDFS找 ...

  9. 自守数算法----C语言实现

    #include <stdio.h> //自守数算法 //ep : 25 ^ 2 = 625 76 ^ 2 = 5776 9376 ^ 2 = 87909376 /*ep : * 376 ...

  10. 05_MyBatis基于注解的开发

     要想开发基于注解的MyBatis应用.需要先写一个带有注解的接口. PersonDao.java的写法如下: package com.rl.dao; import java.util.List; ...