本文介绍了MATLAB ButtonDownFcn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中有一个光学字符识别"项目,需要您的帮助:

I have a project of "Optical Character Recognition" in MATLAB and i need your help:

  1. 当用户在图像上按下鼠标时,我该如何识别?我试图用ButtonDownFcn做到这一点,但是即使我只是打印消息消息未打印.

  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 messagethe message is not printed.

我想允许用户从图像中选择车牌.我该怎么做并保存所选区域的像素?

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?

提前谢谢.

推荐答案

解决您的两个问题:

  1. 我猜您正在尝试设置 数字窗口'ButtonDownFcn' ,将无法正常运行.如果要在用户单击图像时执行某些操作,则应确保设置了图像的rel ="noreferrer"> 'ButtonDownFcn' ,而不是图形窗口或轴对象.请注意图属性文档中的这一行(我加了强调):

  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. 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. Note this line in the figure property documentation (emphasis added by me):

这就是为什么必须为要使用它的每个对象设置一个'ButtonDownFcn'的原因.将其设置为图形窗口将不会使其对图形中的每个对象自动工作.这是为图形和图像对象设置'ButtonDownFcn'的示例:

This is why you have to set a 'ButtonDownFcn' for each object you want it to work for. 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:

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'));

请注意,在图像的内部和外部单击如何显示不同的消息,因为每个都针对不同的对象调用'ButtonDownFcn'.还请注意,如果单击其中一个轴的刻度标记,则不会显示任何内容.这是因为axes对象具有自己的 'ButtonDownFcn' ,没有设置任何内容.

Notice how clicking inside and outside the image displays a different message, since each calls the 'ButtonDownFcn' for a different object. 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.

如果您可以访问图像处理工具箱,则可以使用函数 IMFREEHAND 以使用户绘制ROI(区域为兴趣).然后,您可以使用 createMask方法创建一个二进制文件图像的遮罩,ROI内的像素为1,ROI外的像素为0.

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. 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.

这篇关于MATLAB ButtonDownFcn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 07:31