how to know the type of used OpenCV: CUDA or Kintetic-opencv?

asked 2019-08-26 03:23:41 -0600

Redhwan gravatar image

updated 2019-08-26 06:40:33 -0600

I installed OpenCV and successfully compiled with CUDA using this method Compiling OpenCV with CUDA support after this installed kinetic ROS which includes another OpenCV

when using this method to check from OpenCV version:

>>> import cv2
>>> cv2.__version__

this ros-kinetic-OpenCV version not OpenCV with cuda

the problem my robot is very very very slow when running the code from my desktop (GPU) but when run the code from the computer of the robot (cpu) is very fast.

this is my full code:

#!/usr/bin/env python

import cv2
import numpy as np
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import Image

from cv_bridge import CvBridge, CvBridgeError
bridge = CvBridge()
#cap = cv2.VideoCapture(0)

yellowLower =(136,87,111)
yellowUpper = (180,255,255)

integrated_angular_factor = 0.007;
linear_speed_factor = 200
angular_speed_factor = -0.005

def image_callback(message):
    global integrated_angular_speed,integrated_angular_factor
    frame = bridge.imgmsg_to_cv2(message, "bgr8")

    cv2.namedWindow("Frame", cv2.WINDOW_NORMAL)
    cv2.imshow("Frame", frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):

    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, yellowLower, yellowUpper)
    mask = cv2.erode(mask, None, iterations=2)
    mask = cv2.dilate(mask, None, iterations=2)
    cv2.imshow("Mask", mask)

    _, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

    objects = np.zeros([frame.shape[0], frame.shape[1], 3], 'uint8')
    # move, draw contours
    max_c= None
    max_c_area= 0
    for c in contours:
        area = cv2.contourArea(c)
        if area > 30:
            if area>max_c_area:
                max_c = c
                max_c_area = area
            perimeter = cv2.arcLength(c, True)
            # now we want to draw the centroid, use image moment

            # get centers on x and y
            ((x, y), radius) = cv2.minEnclosingCircle(c)
            x = int(x)
            y = int (y)
            radius = int(radius)
  , (x,y), radius, (0,0,255), 10)
    # print("x= ", x)
    # print('max_c_area= ',max_c_area)
    # print(frame.shape[1])
    if (max_c_area>40):
        velocity_message.linear.x= linear_speed_factor/max_c_area
        Az = (x-frame.shape[1]/2)* angular_speed_factor ;
        integrated_angular_speed +=Az
        if abs(Az)>0.1:
            velocity_message.angular.z= Az + integrated_angular_factor * integrated_angular_speed
            velocity_message.angular.z =0 

    cv2.imshow("Countors", objects)


def camera_listener():
    rospy.Subscriber("/camera/rgb/image_raw", Image, image_callback)

if __name__ == '__main__':
    velocity_message = Twist()

    pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)


how to know what used OpenCV?

how to use OpenCV with Cuda? I read Having trouble using CUDA enabled OpenCV with kinetic but I can't implement it

P.S. Help me or any idea

thank you in advance

edit retag flag offensive close merge delete