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 ...
随机推荐
- THUSC2018滚粗记
THUSC2018滚粗记 前言 大家好,我是\(yyb\),我的博客里又多了一篇滚粗记, 我记得我原来在某篇滚粗记中曾经写过 \(yyb\)还会写很多很多次滚粗记才会有一篇不是滚粗记的东西. 看起来这 ...
- NOIP模拟
1.要选一个{1,2,...n}的子集使得假如a和b在所选集合里且(a+b)/2∈{1,2,...n}那么(a+b)/2也在所选集合里 f[i]=2*f[i-1]-f[i-2]+g[i] g[n]:选 ...
- OpenFlow 消息
消息类型 OpenFlow 的消息共分为三类: Controller-to-Switch 顾名思义,此类消息是由控制器主动发出 Features 用于获取交换机特性 Configuration 用于配 ...
- 代码收藏系列--javascript--移动端技巧
JS判断是否是手机端访问: var is_mobi = navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mm ...
- [CTSC2016]时空旅行
description 题面 solution 线段树分治+斜率优化毒瘤题 题目可以简化为: 你要维护一个包含元素\((x,c)\)的集合 修改操作为从以前的一个版本更新,修改内容为添加或删除一个元素 ...
- LOJ #6036.「雅礼集训 2017 Day4」编码 Trie树上2-sat
记得之前做过几道2-sat裸体,以及几道2-sat前缀优化建图,这道题使用了前缀树上前缀树优化建图.我们暴力建图肯定是n^2级别的,那么我们要是想让边数少点,就得使用一些骚操作.我们观察我们的限制条件 ...
- python 分享文件
http://note.youdao.com/noteshare?id=1787e8bf3a71fca16005ece3e7fffb6c
- 使用jvisualvm工具来监控java运行情况
jvisualvm是jdk自带的工具.所以要先安装jdk 1.jvisualvm工具的路径: 通过which jvisualvm来查看 /usr/local/jdk1.7.0_79/bin/jvi ...
- 「Django」rest_framework学习系列-解析器
满足两个要求,request.Post中才有值 1.请求头要求:请求头中的Content-Type为application/x-www-form-urlencoded 2.数据格式要求 name=x& ...
- Tensorflow BatchNormalization详解:3_使用tf.layers高级函数来构建带有BatchNormalization的神经网络
Batch Normalization: 使用tf.layers高级函数来构建带有Batch Normalization的神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 吴 ...