For some reason its not working within ROS
I am just getting the cap.isOpened() as false
camerao pen failed
no debug message also
Please help, thanks
import sys
import cv2
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
class image_converter:
def __init__(self):
self.image_pub = rospy.Publisher("image_topic_2",Image, queue_size=10)
self.read_cam()
self.bridge = CvBridge()
def read_cam(self):
cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")
print(cap.isOpened())
if cap.isOpened():
cv2.namedWindow("demo", cv2.WINDOW_AUTOSIZE)
while True:
ret_val, cv_image = cap.read();
cv2.imshow('demo',cv_image)
try:
self.image_pub.publish(self.bridge.cv2_to_imgmsg(cv_image, "bgr8"))
except CvBridgeError as e:
print(e)
if cv2.waitKey(1) == ord('q'):
break
else:
print ("camera open failed")
cv2.destroyAllWindows()
def main(args):
ic = image_converter()
rospy.init_node('image_converter', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")
cv2.destroyAllWindows()
if __name__ == '__main__':
print(cv2.getBuildInformation())
Gst.debug_set_active(True)
Gst.debug_set_default_threshold(5)
main(sys.argv)