-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/mcgill-robotics/rover into …
…main
- Loading branch information
Showing
6 changed files
with
710 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export class AppConstants { | ||
// public static get HOST_IP(): string { return '192.168.1.69'; } | ||
public static get HOST_IP(): string { return '192.168.1.69'; } | ||
// public static get HOST_IP(): string { return '10.122.8.160'; } | ||
public static get HOST_IP(): string { return 'localhost'; } | ||
// public static get HOST_IP(): string { return 'localhost'; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
import os, sys | ||
from pydoc_data.topics import topics | ||
#!/usr/bin/env python | ||
|
||
currentdir = os.path.dirname(os.path.realpath(__file__)) | ||
sys.path.append(currentdir) | ||
import rospy | ||
import cv2 | ||
import time | ||
from cv_bridge import CvBridge | ||
from sensor_msgs.msg import Image | ||
from std_msgs.msg import Int16 | ||
from PyQt5 import QtGui | ||
import sys | ||
|
||
stop = False | ||
|
||
class Node_CameraFramePub(): | ||
|
||
def __init__(self): | ||
self.frames = None | ||
self.video_capture = cv2.VideoCapture(0, cv2.CAP_V4L2) | ||
self.video_capture.open(0) | ||
|
||
rospy.init_node('camera_frame_publisher') | ||
self.camera_select_subscriber = rospy.Subscriber("camera_selection", Int16, self.select_camera) | ||
self.timer = rospy.Timer(rospy.Duration(0.03), self.timer_callback) | ||
self.camera_frame_publisher = rospy.Publisher('/camera_frames', Image, queue_size=10) | ||
|
||
def timer_callback(self, event): | ||
try: | ||
ret, frame = self.video_capture.read() | ||
# these code cause error | ||
encode_params = [int(cv2.IMWRITE_JPEG_QUALITY), 90] | ||
result, frame = cv2.imencode(".jpg", frame, encode_params) | ||
self.frames = self.openCV_to_ros_image(frame) | ||
if ret: | ||
print("Publishing frame") | ||
self.camera_frame_publisher.publish(self.frames) | ||
except: | ||
print("No camera found") | ||
finally: | ||
pass | ||
|
||
def openCV_to_ros_image(self, cv_image): | ||
try: | ||
bridge = CvBridge() | ||
ros_image = bridge.cv2_to_imgmsg(cv_image, encoding="passthrough") | ||
return ros_image | ||
except: | ||
print("Cannot translate image correctly") | ||
|
||
def select_camera(self, x): | ||
self.video_capture.release() | ||
self.video_capture.open(x.data * 2) | ||
print(x.data) | ||
|
||
from cv_bridge import CvBridge | ||
import cv2 | ||
|
||
if __name__ == "__main__": | ||
driver = Node_CameraFramePub() | ||
rospy.spin() | ||
def webcam_publisher(): | ||
rospy.init_node('webcam_publisher', anonymous=True) | ||
pub = rospy.Publisher('camera_frames', Image, queue_size=10) | ||
rate = rospy.Rate(30) # 10hz | ||
|
||
cap = cv2.VideoCapture(0) # Open the first webcam | ||
bridge = CvBridge() | ||
|
||
while not rospy.is_shutdown(): | ||
ret, frame = cap.read() | ||
if ret: | ||
# Convert the frame to ROS format | ||
ros_image = bridge.cv2_to_imgmsg(frame, "bgr8") | ||
# Publish the frame | ||
pub.publish(ros_image) | ||
rate.sleep() | ||
|
||
if __name__ == '__main__': | ||
try: | ||
webcam_publisher() | ||
except rospy.ROSInterruptException: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.