Skip to content

Commit

Permalink
增加了launch文件,更改了颜色识别模式(鼠标点击识别)
Browse files Browse the repository at this point in the history
  • Loading branch information
silverbulletmdc committed Nov 18, 2015
1 parent 6a14ed2 commit 873639a
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 59 deletions.
4 changes: 2 additions & 2 deletions build/catkin_generated/setup_cached.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
export CMAKE_PREFIX_PATH="/home/meng/cspm/devel:$CMAKE_PREFIX_PATH"
export CPATH="/home/meng/cspm/devel/include:$CPATH"
export LD_LIBRARY_PATH="/home/meng/cspm/devel/lib:/home/meng/cspm/devel/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"
export PATH="/home/meng/cspm/devel/bin:/opt/ros/indigo/bin:/home/meng/Qt5.5.0/5.5/gcc_64/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
export PATH="/home/meng/cspm/devel/bin:$PATH"
export PKG_CONFIG_PATH="/home/meng/cspm/devel/lib/pkgconfig:/home/meng/cspm/devel/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH"
export PWD="/home/meng/cspm/build"
export PYTHONPATH="/home/meng/cspm/devel/lib/python2.7/dist-packages:$PYTHONPATH"
export ROSLISP_PACKAGE_DIRECTORIES="/home/meng/cspm/devel/share/common-lisp"
export ROS_PACKAGE_PATH="/home/meng/cspm/src:$ROS_PACKAGE_PATH"
export ROS_PACKAGE_PATH="/home/meng/cspm/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks"
2 changes: 1 addition & 1 deletion build/catkin_make.cache
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
face_detect:imu_handler:voice_detect
face_detect:voice_detect
-DCATKIN_DEVEL_PREFIX=/home/meng/cspm/devel -DCMAKE_INSTALL_PREFIX=/home/meng/cspm/install -G Unix Makefiles
2 changes: 0 additions & 2 deletions build/face_detect/CMakeFiles/facedetect.dir/CXX.includecache
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/home/meng/cspm/src/face_detect/src/main.cpp
stdafx.h
/home/meng/cspm/src/face_detect/src/stdafx.h
qt4/Qt/q3accel.h
/home/meng/cspm/src/face_detect/src/qt4/Qt/q3accel.h

/home/meng/cspm/src/face_detect/src/stdafx.h
ros/ros.h
Expand Down
Binary file modified build/face_detect/CMakeFiles/facedetect.dir/src/main.cpp.o
Binary file not shown.
10 changes: 10 additions & 0 deletions cspm启动说明.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1.启动roscore
roscore
2.需要将视频重发布为raw格式
rosrun image_transport republish compressed in:=/camera/image raw out:=/camera/image
3.需要将手柄重发布话题
rosrun topic_tools relay /virtual_joystick/cmd_vel /cmd_vel
4.不要忘记修改ip地址
5.显示图像
rosrun image_view image_view image:=/camera/image _image_transport:=compressed

Binary file modified devel/lib/face_detect/facedetect
Binary file not shown.
11 changes: 11 additions & 0 deletions src/face_detect/launch/cspm.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<launch>

<node pkg="image_view" name="image_view" type="image_view" args="image:=/camera/image _image_transport:=compressed"/>
<node pkg="topic_tools" name="relay" type="relay" args="/virtual_joystick/cmd_vel /cmd_vel"/>
<node pkg="image_transport" name="republish" type="republish" args="compressed in:=/camera/image raw out:=/camera/image"/>




</launch>

11 changes: 11 additions & 0 deletions src/face_detect/launch/cspm.launch~
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<launch>

<node pkg="image_view" name="image_view" type="image_view" args="image:=/camera/image _image_transport:=compressed"/>
<node pkg="topic_tools" name="relay" type="image_view" args="/virtual_joystick/cmd_vel /cmd_vel"/>
<node pkg="image_view" name="image_view" type="image_view" args="image:=/camera/image _image_transport:=compressed"/>
<node pkg="image_view" name="image_view" type="image_view" args="image:=/camera/image _image_transport:=compressed"/>



</launch>

2 changes: 2 additions & 0 deletions src/face_detect/scripts/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def action(img_bytes, img_width, img_height):

# Grab centroid of green ball
ctr,pix_sum = color_tracker.track(img_bytes)
if ctr == (-1,-1):
return (0,0,0,0,0,0)
# Use centroid if it exists
if pix_sum / float(pix_sum_0) > 0.1:
# Compute proportional distance (error) of centroid from image center
Expand Down
117 changes: 80 additions & 37 deletions src/face_detect/scripts/color_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,25 @@
import cv2
import numpy as np


select_point = [0,0]
px_hsv = np.uint8([[[0,0,0]]])
enable_flags = False
select_flags = False
# For OpenCV2 image display
WINDOW_NAME = 'GreenBallTracker'
WINDOW_NAME = 'ColorTracker'
def select_color(event,x,y,flags,param):
global select_point
global enable_flags
global select_flags
if event==cv2.EVENT_LBUTTONDOWN:
select_point=[x,y]
enable_flags = True
select_flags =True
print '我选择了'+str(select_point)+'点'
if event == cv2.EVENT_RBUTTONDOWN:
enable_flags = False
#cv2.setMouseCallback(WINDOW_NAME,select_color)

def track(image):

Expand All @@ -31,66 +48,92 @@ def track(image):
'''

# Blur the image to reduce noise
global select_point
global enable_flags
global select_flags
global px_hsv

image = cv2.resize(image,(640,360))
blur = cv2.GaussianBlur(image, (5,5),0)
if enable_flags:
if select_flags:
px = np.uint8([[image[select_point[1],select_point[0]]]])

# Convert BGR to HSV
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
px_hsv = cv2.cvtColor(px,cv2.COLOR_BGR2HSV)
select_flags = False
print px_hsv[0,0,0]

# Threshold the HSV image for only green colors
lower_green = np.array([40,70,70])
upper_green = np.array([80,200,200])

# Threshold the HSV image to get only green colors
mask = cv2.inRange(hsv, lower_green, upper_green)
if px_hsv[0,0,0]>20 and px_hsv[0,0,0]<235:
lower_color = np.array([px_hsv[0,0,0] - 20,70,70])
upper_color = np.array([px_hsv[0,0,0] + 20,200,200])
elif px_hsv[0,0,0] <= 20:
lower_color = np.array([0,70,70])
upper_color = np.array([px_hsv[0,0,0] + 20,200,200])
elif px_hsv[0,0,0] >=235:
lower_color = np.array([px_hsv[0,0,0] - 20,70,70])
upper_color = np.array([255,200,200])


# Blur the mask
bmask = cv2.GaussianBlur(mask, (5,5),0)
cv2.imshow("bmask",bmask)
# Convert BGR to HSV
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)

# Threshold the HSV image for only green colors

# Take the moments to get the centroid
moments = cv2.moments(bmask)
sum_pix = np.sum(mask)
print sum_pix

m00 = moments['m00']
centroid_x, centroid_y = None, None
if m00 != 0:
centroid_x = int(moments['m10']/m00)
centroid_y = int(moments['m01']/m00)
# Threshold the HSV image to get only green colors
mask = cv2.inRange(hsv, lower_color, upper_color)

# Assume no centroid
ctr = (-1,-1)

# Use centroid if it exists
if centroid_x != None and centroid_y != None:
# Blur the mask
bmask = cv2.GaussianBlur(mask, (5,5),0)
cv2.imshow("bmask",bmask)

ctr = (centroid_x, centroid_y)

# Put black circle in at centroid in image
cv2.circle(image, ctr, 4, (0,0,0))
# Take the moments to get the centroid
moments = cv2.moments(bmask)
sum_pix = np.sum(mask)

# Display full-color image
cv2.imshow(WINDOW_NAME, image)

# Force image display, setting centroid to None on ESC key input
if cv2.waitKey(1) & 0xFF == 27:
ctr = None

# Return coordinates of centroid
return ctr,sum_pix/(255*255*255)
m00 = moments['m00']
centroid_x, centroid_y = None, None
if m00 != 0:
centroid_x = int(moments['m10']/m00)
centroid_y = int(moments['m01']/m00)

# Assume no centroid
ctr = (-1,-1)

# Use centroid if it exists
if centroid_x != None and centroid_y != None:

ctr = (centroid_x, centroid_y)

# Put black circle in at centroid in image
cv2.circle(image, ctr, 4, (0,0,0))

# Display full-color image
cv2.imshow(WINDOW_NAME, image)

# Force image display, setting centroid to None on ESC key input
if cv2.waitKey(1) & 0xFF == 27:
ctr = None

# Return coordinates of centroid
return ctr,sum_pix/(255*255*255)
cv2.imshow(WINDOW_NAME, image)
return (-1,-1),-1

# Test with input from camera
if __name__ == '__main__':
cv2.namedWindow(WINDOW_NAME)

capture = cv2.VideoCapture("test.mp4")

cv2.setMouseCallback(WINDOW_NAME,select_color)
while True:

okay, image = capture.read()


if okay:

if not track(image):
Expand Down
2 changes: 1 addition & 1 deletion src/face_detect/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stdafx.h"
#include "qt4/Qt/q3accel.h"


using namespace std;
using namespace cv;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "stdafx.h"
#include "qt4/Qt/q3accel.h"

using namespace std;
using namespace cv;

Expand Down
16 changes: 0 additions & 16 deletions src/imu_handler/src/stdafx.h

This file was deleted.

0 comments on commit 873639a

Please sign in to comment.