Grab frame from diddyborg stream and view it using imshow

I'm currently playing around with diddyborg follow red ball code. the code runs perfectly on my Pi without those PicoBorg code (removed them for now). I haven't attached my ZeroBorg to the Pi so im currently testing just the video streaming and detection part.

But how do grab the frame and display them on the screen? i wanna see what the camera sees. because i'm planning to use this code as my template for line following robot (follow black line over white background)

can i use something like this? --> cv2.imshow('frame',frame_array)
but i don't know where to implement that method in the code.

it's because the code seems quite complex for my level to understand deeply although i have a pretty basic
understandings of threading that are mostly used in the code.

i hope piborg could help me with this. thanks =)

piborg's picture

You are on the right lines, cv2.imshow is the function you want. You will also need a call like cv2.waitkey to get the window to display correctly.

What I would suggest is adding these calls to the start of the ProcessImage function. For example:

# Image processing function
def ProcessImage(self, image):
    # Show the image before processing
    cv2.imshow('before processing', image)
    cv2.waitkey(1)
    # Get the red section of the image

Thank you so much. that method works well. actually the only line that i've been missing was that cv2.waitKey(1). i didn't realize that the cv2.waitKey(1) was such an important part of displaying images in OpenCV. now i've learned something useful.

I hope that i could use this code for line following purposes since the tracking algorithm for the red ball is quite reliable. do you have any suggestions for me to start with?

piborg's picture

This article is probably a good place to start: http://nzee-wifi.blogspot.co.uk/2013/01/line-following-robot-using-camer...

The logic is fairly easy to follow and should point you in the right direction :)

thanks for the fast response. will try that later =)

Subscribe to Comments for "Grab frame from diddyborg stream and view it using imshow"