简体   繁体   English

MATLAB ButtonDownFcn

[英]MATLAB ButtonDownFcn

I have a project of "Optical Character Recognition" in MATLAB and i need your help: 我在MATLAB中有一个“光学字符识别”项目,需要您的帮助:

  1. how do i recognize when the user press the mouse on an image? 我如何识别用户何时在图像上按下鼠标? i trying to do this with ButtonDownFcn but even when i just printing message the message is not printed. 我试图用ButtonDownFcn做到这一点,但是即使我只是打印消息,消息也不会被打印。

  2. i want to allow the user to select the license plate from the image. 我想允许用户从图像中选择车牌。 how can i do this and save the Pixels of the selected area? 我该怎么做并保存所选区域的像素?

thanks in advance. 提前致谢。

Addressing your two questions: 解决您的两个问题:

  1. I'm guessing that you are trying to set the 'ButtonDownFcn' of the figure window , which won't work how you expect it to. 我猜想您正在尝试设置图形窗口'ButtonDownFcn' ,这将无法按您期望的那样工作。 If you want to do something when the user clicks on an image, you should make sure that you're setting the 'ButtonDownFcn' of the image , and not the figure window or the axes object. 如果要在用户单击图像时执行某些操作,则应确保设置的是图像'ButtonDownFcn' ,而不是图形窗口或轴对象。 Note this line in the figure property documentation (emphasis added by me): 请注意图形属性文档中的这一行(我添加了重点):

    Executes whenever you press a mouse button while the pointer is in the figure window, but not over a child object (ie, uicontrol, uipanel, axes, or axes child) . 每当指针在图形窗口中但不在子对象(即uicontrol,uipanel,axes或axiss child)上方时,只要您按鼠标按钮,便会执行

    This is why you have to set a 'ButtonDownFcn' for each object you want it to work for. 这就是为什么必须为每个要为其工作的对象设置一个'ButtonDownFcn'的原因。 Setting it for the figure window won't make it work automatically for each object in the figure. 将其设置为图形窗口将不会使其对图形中的每个对象自动工作。 Here's an example that sets the 'ButtonDownFcn' for the figure and an image object: 这是为图形和图像对象设置'ButtonDownFcn'的示例:

     img = imread('peppers.png'); %# Load a sample image hFigure = figure; %# Create a figure window hImage = image(img); %# Plot an image set(hFigure,'ButtonDownFcn',... %# Set the ButtonDownFcn for the figure @(s,e) disp('hello')); set(hImage,'ButtonDownFcn',... %# Set the ButtonDownFcn for the image @(s,e) disp('world')); 

    Notice how clicking inside and outside the image displays a different message, since each calls the 'ButtonDownFcn' for a different object. 请注意,在图像的内部和外部单击如何显示不同的消息,因为每个对象都为不同的对象调用'ButtonDownFcn' Notice also that if you click on the tick mark label of one of the axes, nothing is displayed. 还要注意,如果单击其中一个轴的刻度标记,则不会显示任何内容。 This is because the axes object has its own 'ButtonDownFcn' , which wasn't set to anything. 这是因为axes对象具有自己的'ButtonDownFcn' ,未将其设置为任何值。

  2. If you have access to the Image Processing Toolbox you can use the function IMFREEHAND to have the user draw an ROI (region of interest) in the image. 如果您有权使用图像处理工具箱 ,则可以使用功能IMFREEHAND来使用户在图像中绘制ROI(感兴趣区域)。 Then you can use the createMask method to create a binary mask of the image with ones for pixels inside the ROI and zeroes for pixels outside the ROI. 然后,您可以使用createMask方法创建图像的二进制蒙版,其中ROI内的像素为1,ROI内的像素为0。

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

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