VirtualBox issues with USB-CAM and IMAGE-VIEW

asked 2019-11-10 17:02:18 -0600

mhyde64 gravatar image

Hello,

I am currently practicing opencv with ROS. I run it in various VMs with VirtualBox on a Windows Host Machine. Right now I am having some sort of formatting issue when I try and run image-view or my opencv bridge subscriber node.

I am unable to upload images but the out put has static for the top 10th of the screen and the rest is a dull green color. My subscriber node looks like:

#!/home/mhyde/vEnvs/rosPy/bin/python

'''
Run a WebCam Feed Using OpenCV

From the ROS course on Udemy:

https://www.udemy.com/course/ros-essentials/

'''

import sys
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import cv2

bridge = CvBridge()

def imageCallback(imageData):
    '''
    Recieves the image sensor data and converts it to an
    OpenCV format using CV Bridge
    '''
    print 'Received Image'
    #Convert ROS Image into OpenCV Image
    try:
        cvImage = bridge.imgmsg_to_cv2(imageData, "bgr8")
    except CvBridgeError as error:
        print error
    #Now ROS can work directly weith OpenCV

    (rows, cols, channels) = cvImage.shape
    if cols > 200 and rows > 200:
        cv2.circle(cvImage, (100, 100), 90, 255)
    font = cv2.FONT_HERSHEY_SIMPLEX
    cv2.putText(cvImage, "WebCam Activated with ROS + OpenCV",
                (10, 250), font, 1, (255, 255, 255), 2, cv2.LINE_AA)
    cv2.imshow("Image Window", cvImage)
    cv2.waitKey(3)

def main(args):
    '''
    Main Function. Initializes the Subscriber Node for
    Image Processing
    '''
    rospy.init_node('image_converter', anonymous=True)
    imageSub = rospy.Subscriber("/usb_cam/image_raw", Image, imageCallback)
    try:
        rospy.spin()
    except KeyboardInterrupt:
        print "Shutting Down ... "

    cv2.destroyAllWindows()

if __name__ == '__main__':
    main(sys.argv)

I run:

rosrun usb_cam usb_cam_node _pixel_format:=yuvu
rosrun mypkg imagePubSub.py

I have tried in both melodic on ubuntu 18 and kinetic on ubuntu 16 with the same results. I also run into the same error when i simply run

rosrun image_view image_view

I read that someone switch from VMWare to Parallels and it fixed their issue...but I would like to keep working with VirtualBox.

Any Suggestions?

edit retag flag offensive close merge delete