Bad argument (Array should be CvMat or IplImage)
i wrote a node to subscribe to topic imagetopic2 which is publised by a node after using cv bridge to convert to illmage format then i run this node to detect blue color in the image. but i get the error. anyone can help to identify the problem?
Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1308/modules/core/src/array.cpp, line 1238
Traceback (most recent call last):
File "/home/wh07/fuerteworkspace/swri-ros-pkg2/OpenCV/src/Track.py", line 80, in
!/usr/bin/env python
import roslib roslib.loadmanifest('OpenCV') import sys import rospy import cv from stdmsgs.msg import String from sensormsgs.msg import Image from cvbridge import CvBridge, CvBridgeError import cv2 import numpy as np
colortrackerwindow = "Color Tracker"
class ColorTracker:
def __init__(self):
self.image_pub = rospy.Publisher("image_topic_3",Image)
cv.NamedWindow( color_tracker_window, 1 )
self.capture = cv.CaptureFromCAM(0)
self.image_sub = rospy.Subscriber("image_topic_2",Image)
cap = cv2.VideoCapture(0)
while(1):
# Take each frame
_, frame = cap.read()
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of blue color in HSV
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_green, upper_green)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
if name=="main": colortracker = ColorTracker() colortracker.run()
def main(args): ic = imageconverter() rospy.initnode('imageconverter', anonymous=True) try: rospy.spin() except KeyboardInterrupt: print "except shutting down" cv2.destroyAllWindows() if _name__ == 'main':
Asked by daidalos on 2014-01-01 21:51:08 UTC
Comments
you get image from camera and then change the image format and publish. in subscribe node do you change the image format?
Asked by Hamid Didari on 2014-01-03 03:37:30 UTC
yes i converted the image to lpllmage format by following this tutorial http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython
Asked by daidalos on 2014-01-03 18:33:57 UTC
can i see the entire code?
Asked by Hamid Didari on 2014-01-03 20:38:57 UTC