Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] define regions of interest for mouseclicks

edited February 2015 in OpenSesame

Hello,

I can't figure out how to define regions of interest for mouseclicks and would like to ask for help with it.
In my experiment, subjects see a sketchpad with three boxes and are asked to choose between them via clicking on one of them. I first tried to use the touch_response item to collect the mouseclicks, but my supervisor asked me to limit the clickable areas exactly to the three boxes (Image_buttons and form base won't work either because the picture showing the three boxes has to correspond exactly to the last frame of a previous shown video). I think the best way to do this would be using an inline script. Unfortunately I don't know anything about programming, so I am not able to solve this by myself. If given the coordinates of the three boxes, could you provide me with a script to define the regions of interest?

Thanks

Comments

  • edited 7:34AM

    Hi Tabea,

    Don't worry, if you don't know how to program yet. Python is rather easy to learn and you'll be able to do quite a lot after a short while. I'd like to suggest, that you give it a try and do a few online tutorials (there are plenty good ones around, just google).

    Regarding your question, the general idea of what you want is following:

    1) Sample current mouse position and waiting for a click

    2) As soon as mouse gets clicked, take its position and check whether this position lies within the boundaries of one of the 3 ROIs

    2a) Check the first ROI whether it got clicked:
    If the current x-coordinate is bigger the the lower x-boundary AND
    smaller than the upper x-boundary AND the same for the y-coordinates. If every condition is true, you know this ROI was clicked, if at least one of them is false, proceed with the next ROI

    2b) same as 2a, just with different coordinates.

    2c) same as 2a, just with different coordinates.

    In a slightly more pythonic way, it will look something like this:

    # import mouse module
    from openexp.mouse import mouse
    
    # initialize a mouse object
    my_mouse = mouse(exp)
    
    # define helper variables to indicate which ROI was clicked
    ROI1_clicked, ROI2_clicked, ROI3_clicked = False, False, False
    while True:
            # next line corresponds to first point above (sampling and waiting for a click)
            button, position, timestamp = my_mouse.get_click(timeout=20)
            # timeout defines, how long you will wait for a response
    
            # next lines correspond to 2nd point (Checking whether coordinates
            # lie within ROI
            if position[0] >= ROI1_x_min and position[0] <= ROI1_x_max  and \
               position[1] >= ROI1_y_min and position[1] <= ROI1_y_max :
                    ROI1_clicked = True
                    break
            elif ...same for ROI2_x and ROI2_y...:
                    ROI2_clicked = True
                    break
            elif ...same for ROI3_x and ROI3_y...:
                    ROI3_clicked = True
                    break
    
    

    From that point you continue running your script depending on which ROI was clicked.

    It may seem complicated, but it actually isn't. Give it a try, if you need again help, just ask.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited February 2015

    Hello,

    thank you for encouraging me to give Python a try! It was actually quite fun (regarding my blank despair in the beginning).

    The script I finally used looked like this:

    # define ROIs
    ROI_y_min = 546
    ROI_y_max ((and so on))
    
    # import mouse module
    from openexp.mouse import mouse
    
    # initialize a mouse object
    my_mouse = mouse(exp)
    my_mouse.set_visible()
    
    # define helper variables to indicate which ROI was clicked
    ROI1_clicked = False
    ROI2_clicked = False
    ROI3_clicked = False
    
    while True:
        # next line corresponds to first point above (sampling and waiting for a click)
        click, position, timestamp = my_mouse.get_click(timeout=20) 
        if click == None:
            print('No click')
    
        elif ROI1_x_min <= position[0] <= ROI1_x_max and ROI_y_min <= position[1] <= ROI_y_max :
            ROI1_clicked = True
            break
    
        elif ROI2_x_min <= position[0] <= ROI2_x_max and ROI_y_min <= position[1] <= ROI_y_max :
            ROI2_clicked = True
            break
    
        elif ROI3_x_min <= position[0] <= ROI3_x_max and ROI_y_min <= position[1] <= ROI_y_max :
            ROI3_clicked = True
            break
    
    exp.set('ROI1_clicked', ROI1_clicked)
    exp.set('ROI2_clicked', ROI2_clicked)
    exp.set('ROI3_clicked', ROI3_clicked)
    exp.set('ans_time', timestamp)
    
  • edited 7:34AM

    Great to hear. And thanks for sharing your solution.

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games