简体   繁体   English

在OCTAVE中获取鼠标位置

[英]Obtain mouse position in OCTAVE

I am using OCTAVE on my PC for image processing and display. 我在我的电脑上使用OCTAVE进行图像处理和显示。 I am reading in a .pgl file and converting it from rgb to gray to obtain a simple 2D array. 我正在读取.pgl文件并将其从rgb转换为灰色以获得简单的2D数组。 I then display this using imagesc(). 然后我使用imagesc()显示它。 What I'd like to do is use the mouse to click on a particular part of the image and return where the mouse was clicked in the array ((x,y) coordinates). 我想要做的是使用鼠标单击图像的特定部分,并返回在数组((x,y)坐标中单击鼠标的位置)。 I've tried using ginput() which I think should work if I understand the documentation correctly. 我已经尝试过使用ginput(),如果我正确理解文档,我认为应该可以使用。 But I can't get it to work. 但我无法让它发挥作用。 Usually I have to control C out once I type in [x,y] = ginput(1), for example, because the prompt never returns in my input window no matter how many mouse clicks I do in the display (or returns in the input window - I have to control C out). 例如,一旦输入[x,y] = ginput(1),我就必须控制C输出,因为无论我在显示屏上点击多少鼠标(或者返回输入窗口 - 我必须控制C out)。 First is this do-able? 首先是这样做吗? or am I attempting something OCTAVE just can't do? 或者我尝试OCTAVE的事情是做不到的? If so, how? 如果是这样,怎么样?

This should work with ginput and the FLTK toolkit. 这应该适用于ginput和FLTK工具包。 What version of Octave are you using on which OS? 你在哪个操作系统上使用什么版本的Octave? To make sure you are using FLTK toolkit use 确保使用FLTK工具包

close all
graphics_toolkit fltk

at the beginning of your script. 在脚本的开头。

The thing to remember with ginput() is that after clicking with the mouse in the plot window, you have to hit return key on the keyboard if the n parameter is not stated. 使用ginput()记住的事情是,在绘图窗口中单击鼠标后,如果未指定n参数,则必须按键盘上的返回键。 After the return, the coordinates will be returned in the x,y vars. 返回后,坐标将在x,y变量中返回。 Also the button used to click will be returned when called with [x,y,buttons]=ginput(n). 当使用[x,y,buttons] = ginput(n)调用时,将返回用于单击的按钮。 The 'n' argument controls the number of clicks to watch for before recording the coords. 'n'参数控制在录制coords之前要监视的点击次数。 Works well in Octave 4.0.1. 适用于Octave 4.0.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM