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 ...
随机推荐
- 🔺 Garbage Remembering Exam UVA - 11637()
题目大意:给你N个单词,有两种方法随机排列,一种随机排成一行,另一种随机排成一圈,当两个单词之间的距离在两种排列中都严格小于K时,则这两个单词构成无效单词,问无效单词的期望. 解题思路:首先对于一排单 ...
- Spring Boot系列教程二:创建第一个web工程 hello world
一.创建工程 创建名称为"springboot_helloworld"的spring boot工程, new->Spring Starter Project,直接上图 ...
- BZOJ3261:最大异或和——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=3261 给定一个非负整数序列{a},初始长度为N. 有M个操作,有以下两种操作类型: 1.A x:添加 ...
- NOIP2017 考前汇总
时隔一年,相比去年一无所知的自己,学到了不少东西,虽然还是很弱,但也颇有收获[学会了打板QAQ] 现在是2017.11.9 21:10,NOIP2017的前两天晚上,明天就要出发,做最后的总结 N ...
- MySQL用户授权
一.授权语法格式 grant 权限列表 on 数据库名.表名 to '用户名'@'客户端主机' [identified by '密码']; 单词: privileges [ˈprivilidʒz] ...
- centos 6.5 web service模式 系统 安装php
1 首先是坚持libxml2出问题,提示如下: checking for xml2-config path... /home/www/thirdlib/libxml2/bin/xml2-configc ...
- CDOJ--1550&&1731
原题链接:http://acm.uestc.edu.cn/problems.php?vol=15 分析:首先筛出sqrt(2^31-1)以内的素数,对于给定的区间[L,R],仍然用筛素数的思想把那些是 ...
- CodeChef DGCD
You're given a tree on N vertices. Each vertex has a positive integer written on it, number on the i ...
- hihocoder 1509异或排序
描述 给定一个长度为 n 的非负整数序列 a[1..n] 你需要求有多少个非负整数 S 满足以下两个条件: (1).0 ≤ S < 2^60 (2).对于所有 1 ≤ i < n ,有 ( ...
- 手脱nSPack 2.2
1.PEID查壳 深度扫描下:nSPack 2.2 -> North Star/Liu Xing Ping 2.载入OD,上来就是一个大跳转,F8单步跟下去 0040101B >- E9 ...