开发者

MATLAB ButtonDownFcn

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

    开发者_高级运维
  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.

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

    Executes whenever you press a mouse button while the pointer is in the figure window, but not over a child object (i.e., uicontrol, uipanel, axes, or axes child).

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

    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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜