Bad argument (Array should be CvMat or IplImage) [closed]

asked 2014-01-01 20:51:08 -0500

daidalos gravatar image

i wrote a node to subscribe to topic image_topic_2 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/fuerte_workspace/swri-ros-pkg2/OpenCV/src/Track.py", line 80, in <module> color_tracker.run() File "/home/wh07/fuerte_workspace/swri-ros-pkg2/OpenCV/src/Track.py", line 39, in run hsv_img = cv.CreateImage(cv.GetSize(img), 8, 3) cv2.error: Array should be CvMat or IplImage

#!/usr/bin/env python import roslib roslib.load_manifest('OpenCV') import sys import rospy import cv from std_msgs.msg import String from sensor_msgs.msg import Image from cv_bridge import CvBridge, CvBridgeError import cv2 import numpy as np

color_tracker_window = "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__": color_tracker = ColorTracker() color_tracker.run()

def main(args): ic = image_converter() rospy.init_node('image_converter', anonymous=True) try: rospy.spin() except KeyboardInterrupt: print "except shutting down" cv2.destroyAllWindows() if __name__ == '__main__':

edit retag flag offensive reopen merge delete

Closed for the following reason OpenCV Question: THe OpenCV community prefers to answer questions at: http://answers.opencv.org/questions/ by tfoote
close date 2016-11-09 13:18:29.758437

Comments

you get image from camera and then change the image format and publish. in subscribe node do you change the image format?

Hamid Didari gravatar image Hamid Didari  ( 2014-01-03 02:37:30 -0500 )edit

yes i converted the image to lpllmage format by following this tutorial http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython

daidalos gravatar image daidalos  ( 2014-01-03 17:33:57 -0500 )edit

can i see the entire code?

Hamid Didari gravatar image Hamid Didari  ( 2014-01-03 19:38:57 -0500 )edit