how to: drawing image/png (with draw_gl_texture)

103 views
Skip to first unread message

Michael Barz

unread,
Nov 18, 2013, 3:48:13 AM11/18/13
to pupil-...@googlegroups.com

Hello,

I'd like to draw an image within a plugin window.
Using draw_gl_texture, which works for camera frames, resulted in a sheared version of my image.

Here some code:
 def __init__(self):
    ...
    self._refimg = cv2.imread("marker/marker01.jpg")
    ...


def gl_display_in_window(self):
    ...
    draw_gl_texture(self._refimg)
    ...


Do I have to set some flags, when loading the image? Or is it due to the draw_gl_texture function?


Thanks and kind regards,
Michael

Moritz Kassner

unread,
Nov 18, 2013, 4:08:34 AM11/18/13
to pupil-...@googlegroups.com
Hi Michael,

this is exactly the way you are supposed to do it. I just tried and it works fine for me. The image is stretched to the aspect ratio of the window but not sheared/skewed (see attachment).


What OS are you using? Make sure your image has 3(BGR/RGB) or 4(BGRA/RGBA) channels. Are you modifying the image in any way? 
Could you send a screenshot?

best,

Moritz
Inline image 1



--
You received this message because you are subscribed to the Google Groups "pupil-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pupil-discus...@googlegroups.com.
To post to this group, send email to pupil-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pupil-discuss/87539a92-a199-4fc1-8335-4d7cc8653d00%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

img_inside_plugin_window.jpg

Michael Barz

unread,
Nov 18, 2013, 4:28:42 AM11/18/13
to pupil-...@googlegroups.com, moritz...@googlemail.com
Hi, thanks for the fast response.

I use Ubunto13.10/GNOME x64.

And that's what I get...

Moritz Kassner

unread,
Nov 18, 2013, 4:48:00 AM11/18/13
to Michael Barz, pupil-...@googlegroups.com
Hi,

I tried on my Ubuntu machine as well and dont have your behavior. Lets see.. Could you send me the png you are using in this screenshot?

m

Michael Barz

unread,
Nov 18, 2013, 4:54:04 AM11/18/13
to pupil-...@googlegroups.com, Michael Barz, moritz...@googlemail.com
Hi,

I used markers from the following website:
http://www.lmt.ei.tum.de/team/mitarbeiter/florian-schweiger/inhalte/forschungsthemen/maximum-detector-response-markers-for-surf.html

I just generated the sample set of markers and used the first one from the first row. With the standard pdf viewer I opened the file and saved the image as a png.

Kind regards,
Michael

Moritz Kassner

unread,
Nov 18, 2013, 6:16:30 AM11/18/13
to Michael Barz, pupil-...@googlegroups.com
Alright,

when I follow your workflow I get the same skewed result. In fact any image I create on linux will do this. However, images I download look just fine. Try any jpg from google image search.

Explicitly setting the GL_UNPACK_ALIGNMENT to 1 (byte-alignment) before creating the texture in gl_utils.py fixes this issue. 

I have pushed this fix into MASTER, pulling from github.com/pupil-labs/pupil now should fix your problem!

best,

Moritz



Michael Barz

unread,
Nov 18, 2013, 6:27:04 AM11/18/13
to pupil-...@googlegroups.com, Michael Barz, moritz...@googlemail.com
Hi, thanks for you reply.
I just created a new image with gimp... added a white border around the marker.
Now drawing works fine.

Kind regards,
Michael

Moritz Kassner

unread,
Nov 18, 2013, 6:31:57 AM11/18/13
to Michael Barz, pupil-...@googlegroups.com
Does it work with the .png you used before now as well?

I m currently working on marker detection for Pupil, how fast/reliable do you expect theses maximum response SUFT detectors this to be?

best,

Moritz

Michael Barz

unread,
Nov 18, 2013, 6:46:45 AM11/18/13
to pupil-...@googlegroups.com, Michael Barz, moritz...@googlemail.com
Hello,

extracting features on the whole field image is very expensive. I got 7 frames per second.
Now I try to find a region of interest by means of a white border.

I'm not that familiar with openCV, thus it could take a while till I finish with that.

Michael

Moritz Kassner

unread,
Nov 18, 2013, 7:01:13 AM11/18/13
to Michael Barz, pupil-...@googlegroups.com
Hi Michael,

Alright, thats good to know!

Maybe resizing the img for a preliminary search could help:

small_img  = img[::2,::2] # looking at every second pixel will reduce cpu load considerably. 

]then you can look at subregions of the full res img (have a look at the Region of Interest (ROI) class in methods.py)

best,

Moritz



Michael Barz

unread,
Nov 19, 2013, 3:52:04 AM11/19/13
to pupil-...@googlegroups.com, Michael Barz, moritz...@googlemail.com
Hi, thanks for your help.
I'm now able to recognize the display, or at least the marker with its white border.
I'll take this region as mask for feature extraction, or is it more efficient to extract the region of interest?

Here is my code:

small = frame.img[::4, ::4]

            gray = cv2.cvtColor(small, cv2.COLOR_RGB2GRAY)
            #blur = cv2.medianBlur(gray, 5)
            blur = cv2.blur(gray, (5,5))
            #threshold, binary = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
            threshold, binary = cv2.threshold(blur, 150, 255, cv2.THRESH_BINARY)

            contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            mask = np.zeros(small.shape, np.uint8)
            count = 0
            for h,cnt in enumerate(contours):
                arclength = cv2.arcLength(cnt, True)
                if arclength > self._max_rect:
                    self.max_rect = arclength
                   
                approx = cv2.approxPolyDP(cnt, 0.1*arclength, True)
                if arclength > 0.6 * self._max_rect and len(approx) == 4:
                    cv2.drawContours(mask, [cnt], 0, (255, 255, 255), -1)
                    count = count + 1
                    #cv2.fillConvexPoly(mask, approx, (255, 255, 255))
            mask = cv2.split(mask)[0]

Kind regards,
Michael

Moritz Kassner

unread,
Nov 19, 2013, 4:37:30 AM11/19/13
to Michael Barz, pupil-...@googlegroups.com
HI Michael,

this is what we worked on this morning :-)  Almost the same thing!


we look for markers like these:Inline image 2
On top are the detected and projected markers.

We hope to release surface and screen tracking soon!

best,

Moritz



marker_WIP.jpg

Michael Barz

unread,
Nov 19, 2013, 5:29:21 AM11/19/13
to pupil-...@googlegroups.com, Michael Barz, moritz...@googlemail.com
Hi, looks great.

Especially your fps value is much better than mine.
I'll try to improve my approach. Cannot harm my openCV skills when working with it ;)

If there's something new I'll put my results here.

Kind regards,
Michael
Reply all
Reply to author
Forward
0 new messages