Closed 646145192 closed 2 years ago
It is because the detect.py thinks the image received is BGR format. So, at detect.py line 264
img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416
it will convert the image to RGB format for inference.
And when publishing, it will publish BGR version.(line 349)
img_msg = self.bridge.cv2_to_imgmsg(im0, encoding="bgr8")
Try to modify line 264 to img = img[:, :, ::-1] img.transpose(2, 0, 1) and modify line 349 to "rgb8" and I think you can get the right color.
I tried your method but the following problem occurred
If I change line 264
img = img.transpose(2, 0, 1)
and change line 349
img_msg = self.bridge.cv2_to_imgmsg(im0, encoding="rgb8")
It works fine but the color issue persists
line 264 should be
img = img[:, :, ::-1]
.transpose(2,0,1) is used for covert bgr to rgb.
if i use
img = img[:, :, ::-1]
as line 264
error persists
It seems that the image is not the right size without transpose
You are right and I made a mistake. [:, :, ::-1] is used for covert bgr to rgb and transpose is for the right shape. Add code before line 349 to see if rviz have any changes.
im0 = im0[:, :, ::-1]
img_msg = self.bridge.cv2_to_imgmsg(im0, encoding="rgb8")
it's still the wrong color...
whether i use img = img[:, :, ::-1].transpose(2, 0, 1)
or img = img.transpose(2, 0, 1)
in line 264
and I have add im0 = im0[:, :, ::-1]
before 349
This is too weird. Did the topic you watch is /detections_image ?
/detections_image_topic
not exactly the same as yours
:joy: I will have a test tomorrow.
ok thank you very much
I have updated the repo. I think it is right now. Just have a try
!
Now the color is normal,thank you very much!
Hi! When I run your program, the wrong color appears. Do you know the reason? The rgb information of the camera looks correct in rviz, but the color is reversed in yolo. I am using a realsense D455 camera. Looking forward to your reply!![2022-06-20 17-19-44 的屏幕截图](https://user-images.githubusercontent.com/74187736/174569815-c09a8c65-6ed3-4b33-ba64-c54154fa7aec.png)