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 ...
随机推荐
- 【BZOJ2109/2535】【NOI2010】航空管制(贪心)
[BZOJ2109/2535][NOI2010]航空管制(贪心) 题面 BZOJ2109 BZOJ2535 题解 很好玩的一道题目 先看第一问,显然是要找一个合法的拓扑排序的序列. 直接拓扑排序,把队 ...
- 洛谷 P3723 [AH2017/HNOI2017]礼物 解题报告
P3723 [AH2017/HNOI2017]礼物 题目描述 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手环,一个留给自己,一个送给她.每个手环上各有 \(n\) 个 ...
- 洛谷 P2505 [HAOI2012]道路 解题报告
P2505 [HAOI2012]道路 题目描述 C国有n座城市,城市之间通过m条单向道路连接.一条路径被称为最短路,当且仅当不存在从它的起点到终点的另外一条路径总长度比它小.两条最短路不同,当且仅当它 ...
- MapReduce(五) mapreduce的shuffle机制 与 Yarn
一.shuffle机制 1.概述 (1)MapReduce 中, map 阶段处理的数据如何传递给 reduce 阶段,是 MapReduce 框架中最关键的一个流程,这个流程就叫 Shuffle:( ...
- 《剑指offer》— JavaScript(10)矩形覆盖
矩形覆盖 题目描述 我们可以用(2*1)的小矩形横着或者竖着去覆盖更大的矩形.请问用n个(2*1)的小矩形无重叠地覆盖一个(2*n)的大矩形,总共有多少种方法? 实现代码 function jumpF ...
- Codeforces 894.C Marco and GCD Sequence
C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Linux环境编译动态库和静态库总结
对Linux环境动态库和静态库的一些基础知识做一些总结, 首先总结静态库的编译步骤. 1 先基于.cpp或者.c文件生成对应的.o文件 2将几个.o文件 使用ar -cr命令 生成libname.a文 ...
- 题解【luogu3709 大爷的字符串题】
Description 个人觉得这是这道题最难的一步...出题人的语文... 每次给出一个区间,求这个区间最少能被多少个单调上升的序列覆盖. Solution 这个东西可以转化为这个区间中出现次数最多 ...
- discuz开发,登录次数过多,锁定解决方法
到数据库里的表找到pre_common_failedlogin 和pre_ucenter_failedlogins清空里面的内容即可. truncate table pre_common_failed ...
- 「PLC」PLC的硬件与工作原理