c++鼠标点点,获取坐标值,放入到txt文件中
// oj3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<opencv2\opencv.hpp>
#include<opencv2/imgproc/types_c.h>
#include <opencv2\objdetect\objdetect_c.h>
#include <fstream>
using namespace cv;
using namespace std;
struct my3dim
{
int x;
int y;
int label;
};
vector<my3dim> mypoint1;
vector<my3dim> mypoint2;
vector<CvPoint> points1;
vector<CvPoint> points2;
vector<CvPoint> points3;
Mat expanded, img1, img2;
Point cent;
my3dim mytmp;
void onmouse(int event, int x, int y, int flag, void *img)//鼠标事件回调函数,鼠标点击后执行的内容应在此
{
switch (event)
{
case EVENT_LBUTTONDOWN://鼠标左键按下事件
cent.x = x;
cent.y = y;
mytmp.x = x;
mytmp.y = y;
mytmp.label = 1;
circle(img1, cent, 2, Scalar(255, 255, 0), 3);
cout << "第一个 " << x << " " << y << endl;
points1.push_back(CvPoint(x, y));
mypoint1.push_back(mytmp);
break;
case EVENT_RBUTTONDOWN://鼠标左键按下事件
cent.x = x;
cent.y = y;
mytmp.x = x;
mytmp.y = y;
mytmp.label = -1;
circle(img1, cent, 2, Scalar(255, 0, 0), 3);
cout << "第一个 " << x << " " << y << endl;
points1.push_back(CvPoint(x, y));
mypoint1.push_back(mytmp);
break;
default:
break;
}
}
void onmouse2(int event, int x, int y, int flag, void *img)//鼠标事件回调函数,鼠标点击后执行的内容应在此
{
switch (event)
{
case EVENT_LBUTTONDOWN://鼠标左键按下事件
cout << "第二个 " << x << " " << y << endl;
points2.push_back(CvPoint(x, y));
break;
case EVENT_LBUTTONUP:
break;
default:
break;
}
}
void onmouse3(int event, int x, int y, int flag, void *img)//鼠标事件回调函数,鼠标点击后执行的内容应在此
{
switch (event)
{
case EVENT_LBUTTONDOWN://鼠标左键按下事件
cout << "第二个 " << x << " " << y << endl;
points3.push_back(CvPoint(x, y));
cent.x = x;
cent.y = y;
if (x <= img1.cols)
circle(expanded, cent, 2, Scalar(255, 0, 0), 3);
else
circle(expanded, cent, 2, Scalar(0, 0, 255), 3);
break;
default:
break;
}
//imshow("combined", expanded);
}
int main()
{
img1 = imread("E:\\zhouliyang\\fordebug\\MVS\\data\\1452252565655\\back\\key\\00009.jpg");//读取图像
//从文件中读入图像
img2 = imread("E:\\zhouliyang\\fordebug\\MVS\\data\\1452252565655\\side2\\key\\00000.jpg");//读取图像
namedWindow("第一个图像");//窗口
//namedWindow("第二个图像", WINDOW_NORMAL);//窗口
setMouseCallback("第一个图像", onmouse, &img1);//注册鼠标事件到“鼠标画个框”窗口,即使在该窗口下出现鼠标事件就执行onmouse函数的内容,最后一个参数为传入的数据。这里其实没有用到
//setMouseCallback("第二个图像", onmouse2, &img2);
imshow("第一个图像", img1);
while (true)
{
imshow("第一个图像", img1);
int key = waitKey(10);
if (key == 27)
break;
//expanded = srcImg.clone();
}
destroyAllWindows();
fstream outfile("G:\\download\\points.txt");
if (!outfile)
{
cout << "unable open outfile" << endl;
exit(1);
}
for (int i = 0; i < mypoint1.size(); i++)
{
outfile << mypoint1[i].x << "\t" << mypoint1[i].y << "\t"<<mypoint1[i].label<<endl;
}
outfile.close();
return 0;
}
c++鼠标点点,获取坐标值,放入到txt文件中的更多相关文章
- zedgraph控件怎么取得鼠标位置的坐标值(转帖)
我想取得zedgraph控件上任意鼠标位置的坐标值,IsShowCursorValues可以显示鼠标位置的值但是不能提取赋值给其他的变量.用PointValueEvent这个事件又只能得到已经画出的点 ...
- 键盘录入一个文件夹路径,统计该文件夹(包含子文件夹)中每种类型的文件及个数,注意:用文件类型(后缀名,不包含.(点),如:"java","txt")作为key, 用个数作为value,放入到map集合中,遍历map集合
package cn.it.zuoye5; import java.io.File;import java.util.HashMap;import java.util.Iterator;import ...
- android 中对于采用okhttp时获取cookie并放入webview实现跳过登陆显示页面的功能
最近项目需要将网页的一些信息展示到app当中,由于采用的是okhttp进行网络的访问,并采用了cookie对于每次的访问请求都做了验证,所以在加入webview显示网页的时候会需要进行一下验证,为了跳 ...
- LinuxC语言读取文件,分割字符串,存入链表,放入另一个文件
//file_op.c #include <string.h> #include <stdio.h> #include <stdlib.h> struct info ...
- git如何删除已经 add 的文件 (如何撤销已放入缓存区文件的修改)
使用 git rm 命令即可,有两种选择, 一种是 git rm –cached “文件路径”,不删除物理文件,仅将该文件从缓存中删除: 一种是 git rm –f “文件路径”,不仅将该文件从缓存中 ...
- 自定义的类型放入STL的set中,需要重载自定义类中的“<”符号(转)
在以前学习STL的时候,曾经学到过,如果要将自定义的类型放入到set中的话,就需要重载“<”符号,原因是set是一个有序的集合,集合会按照“<”比较的大小,默认按照从小到大的顺序排列.假设 ...
- 获取TXT文件,解决读取TXT乱码问题,查找所输入字是否在TXT文件中,
/// <summary> /// 查看是否存在 /// </summary> /// <param name="str"></param ...
- Android 之 PackageManager获取的应用程序信息与AndroidManifest文件中设置的信息不一致问题
有时我们需要用 PackageManager 来获取应用程序的版本号和版本名称等信息,通过以下代码来获取: PackageManager manager = getPackageManager(); ...
- 获取微信签名,并保存在xml文件中
using System; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using Sys ...
随机推荐
- Mybatis笔记二:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
错误异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.dao.N ...
- A2W W2A等所需要的文件
1.包含头文件 #include <atlbase.h> #include <atlconv.h> 2.在使用前加上,注意,不是在文件都定义. USES_CONVERSION;
- Kerberos的黄金票据详解
0x01黄金票据的原理和条件 黄金票据是伪造票据授予票据(TGT),也被称为认证票据.如下图所示,与域控制器没有AS-REQ或AS-REP(步骤1和2)通信.由于黄金票据是伪造的TGT,它作为TGS- ...
- HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)
HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...
- Ciesz się Polską
SZKOpułPoi at BZOJPA at BZOJONTAK at BZOJ Chinese Solution of Poi
- 徒手创建一个 jsp 项目
在开始之前,先回顾一下 jsp 和 servlet,jsp 和 servlet 本质是一样的,因为 jsp 最终必须编译成 servlet 才能运行. 因为 jsp 的那些标签 jvm 是无法直接运行 ...
- Leetcode 492. 构造矩形
1.题目描述 作为一位web开发者, 懂得怎样去规划一个页面的尺寸是很重要的. 现给定一个具体的矩形页面面积,你的任务是设计一个长度为 L 和宽度为 W 且满足以下要求的矩形的页面.要求: 1. 你设 ...
- 「Linux」centos7安装uWSGI
一定要记得先安装python-devel,再安装uWSGI,否则即使安装成功也是不能使用的,切记切记
- Data science blogs
Data science blogs A curated list of data science blogs Agile Data Science http://blog.sense.io/ (RS ...
- 使用TortoiseGit时如何实现SSH免密码登录
1. Git配置 连接GIT服务器使用的是SSH连接,因此无密码登录,需要使用公钥和私钥. 1) 生成公钥/私钥 在Git Shell中输入ssh-keygen命令,直接回车使用默认 ...