imshow() function in opencv not working.

i am using opencv-2.4 ,with my web cam LogitechC170 in my BBB and trying to grab image in a window by using imshow() function.But it gets hanged .If i remove the webcam from usb it ends up with image window blanked .i am using
I dont know this question fits in this forum or not but same peice of code is running in my laptop /ubuntu-1410. Please help.