opencv , Ptython detect two objects at the same time

THIS PROJECT MUST WITHOUT EXCEPTION USE OPENCV & PYTHON...I am trying to track a player and object in the same frame/video/camera...ultimately camera only ... using KCF for now to track the player, but will not track ball

import cv2

import sys

import imutils

if __name__ == '__main__' :

tracker_types = ['KSF ']

tracker_type = tracker_types[0]

tracker = cv2.TrackerKCF_create()

# Read video

video = [login to view URL]("[login to view URL]")

# Exit if video not opened.

if not [login to view URL]():

print ("Could not open video")

[login to view URL]()

# Read first frame.

ok, frame = [login to view URL]()

frame = [login to view URL](frame, width= 720)

#frame = [login to view URL](frame, height= 720)

if not ok:

print ('Cannot read video file')

[login to view URL]()

# Define an initial bounding box

bbox = (320, 230, 230, 320)

# Uncomment the line below to select a different bounding box

#bbox = [login to view URL](frame, False)

# Initialize tracker with first frame and bounding box

ok = [login to view URL](frame, bbox)

while True:

# Read a new frame

ok, frame = [login to view URL]()

if not ok:


# Start timer

timer = [login to view URL]()

# Update tracker

ok, bbox = [login to view URL](frame)

# Calculate Frames per second (FPS)

fps = [login to view URL]() / ([login to view URL]() - timer);

# Draw bounding box

if ok:

# Tracking success

p1 = (int(bbox[0]), int(bbox[1]))

p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3]))

[login to view URL](frame, p1, p2, (255,0,0), 2, 1)

else :

# Tracking failure

[login to view URL](frame, "Tracking failure detected", (100,80), cv2.FONT_HERSHEY_SIMPLEX, 0.75,(0,0,255),2)

# Display tracker type on frame

[login to view URL](frame, tracker_type + " Tracker", (100,20), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50),2);

# Display FPS on frame

[login to view URL](frame, "FPS : " + str(int(fps)), (100,50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2);

# Display result

[login to view URL]("Tracking", frame)

colorLower = (91,45,58)

colorUpper = (90,33,93)

# Start with LED off

# loop over the frames from the video stream

while True:

# grab the next frame from the video stream, Invert 180o, resize the

# frame, and convert it to the HSV color space

frame = [login to view URL]()

frame = [login to view URL](frame, width=500)

frame = [login to view URL](frame, height=700)

hsv = [login to view URL](frame, cv2.COLOR_BGR2HSV)

# construct a mask for the object color, then perform

# a series of dilations and erosions to remove any small

# blobs left in the mask

mask = [login to view URL](hsv, colorLower, colorUpper)

mask = [login to view URL](mask, None, iterations=2)

mask = [login to view URL](mask, None, iterations=2)

# find contours in the mask and initialize the current

# (x, y) center of the object

cnts = [login to view URL]([login to view URL](), cv2.RETR_EXTERNAL,


#cnts = cnts[0] if imutils.is_cv2() else cnts[1]

center = None

# only proceed if at least one contour was found

if len(cnts) > 0:

# find the largest contour in the mask, then use

# it to compute the minimum enclosing circle and

# centroid

c = max(cnts, key=[login to view URL])

((x, y), radius) = [login to view URL](c)

M = [login to view URL](c)

center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))

# only proceed if the radius meets a minimum size

if radius > 10:

# draw the circle and centroid on the frame,

# then update the list of tracked points

[login to view URL](frame, (int(x), int(y)), int(radius),

(0, 255, 255), 2)

[login to view URL](frame, center, 5, (0, 0, 255), -1)

# show the frame to our screen

[login to view URL]("Frame", frame)

print("\n [INFO] Exiting [embed=file 1415770][embed=file 1415771]Program and cleanup stuff \n")

[login to view URL]()

[login to view URL]()

Skills: OpenCV, Python, Software Architecture

See more: detect objects algorithm, detect objects image, detect objects picture crop matlab, simple object detection pyimagesearch, opencv object tracking, opencv multitracker python, opencv object detection python, pyimagesearch object detection, multiple object detection opencv python, real time object detection opencv python, opencv detection, opencv edge detect, opencv measure distance objects, opencv face detect video, detect idle time air, adobe air detect idle time, detect objects opencv, java opencv eye detect, opencv java detect features, opencv logo detect

About the Employer:
( 19 reviews ) baltimore, United States

Project ID: #19026758

Awarded to:


Hi there! I'm very interested in your job. I have lots of experience in computer vision such as object detection as well as object tracking. And also I have developed many applications of python and OpenCV. I sure More

$166 USD in 3 days
(13 Reviews)

7 freelancers are bidding on average $255 for this job


Hello! I saw your attachment: the detection result and check your code by openCV tracker. Frankly speaking, there is more efficient method of object detection. Do you know deep learning? did you hear YOLO? YOLO can More

$400 USD in 3 days
(18 Reviews)

Hi, How are you. These are some projects that i completed before. Plz check it. [login to view URL] I'm very interested in your job. I am an expert of machine l More

$400 USD in 3 days
(15 Reviews)

First:- Chatbot --> This can be integrated by any Facebook page, Slack etc. Its main aim is to reduce the human effort. For example, if this Chatbot is integrated with company page so it can easily answer you some b More

$155 USD in 3 days
(2 Reviews)

~~~ Welcome to your visit to my profile! ~~~ Hi, nice to meet you. I am very interested in your project. I have extensive experiences in Image processing and computer vision such as object detection, image recogniti More

$300 USD in 3 days
(3 Reviews)

Hello I am professional developer..I can develop this for you. let me discuss right now.I am ready to do that for you

$111 USD in 3 days
(0 Reviews)

Similar project:...................................................................................................................... [login to view URL]

$250 USD in 10 days
(0 Reviews)