Jump to content

Python computer vision help i just started out

Symbolls

Hello so i have been galowing a tutorial on computer vison (https://www.murtazahassan.com/courses/opencv-with-python-for-beginners/lesson/object-tracking/) for object traking i downloaded the code witch is

 

import cv2

############### Tracker Types #####################

# tracker = cv2.TrackerBoosting_create()
# tracker = cv2.TrackerMIL_create()
# tracker = cv2.TrackerKCF_create()
# tracker = cv2.TrackerTLD_create()
# tracker = cv2.TrackerMedianFlow_create()
# tracker = cv2.TrackerCSRT_create()
tracker = cv2.TrackerMOSSE_create()

########################################################


cap = cv2.VideoCapture(1)
# TRACKER INITIALIZATION

success, frame = cap.read()
bbox = cv2.selectROI("Tracking", frame, False)
tracker.init(frame, bbox)


def drawBox(img, bbox):
    x, y, w, h = int(bbox[0]), int(bbox[1]), int(bbox[2]), int(bbox[3])
    cv2.rectangle(img, (x, y), ((x + w), (y + h)), (255, 0, 255), 3, 3)
    cv2.putText(img, "Tracking", (100, 75), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)


while True:

    timer = cv2.getTickCount()
    success, img = cap.read()
    success, bbox = tracker.update(img)

    if success:
        drawBox(img, bbox)
    else:
        cv2.putText(img, "Lost", (100, 75), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

    cv2.rectangle(img, (15, 15), (200, 90), (255, 0, 255), 2)
    cv2.putText(img, "Fps:", (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 0, 255), 2);
    cv2.putText(img, "Status:", (20, 75), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 0, 255), 2);

    fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer);
    if fps > 60:
        myColor = (20, 230, 20)
    elif fps > 20:
        myColor = (230, 20, 20)
    else:
        myColor = (20, 20, 230)
    cv2.putText(img, str(int(fps)), (75, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.7, myColor, 2);

    cv2.imshow("Tracking", img)
    if cv2.waitKey(1) & 0xff == ord('q'):
        break

i am using pycahrm btw and i keep having this error

 

File "C:\Users\symbo\PycharmProjects\OpencvTest\main.py", line 11, in <module>
    tracker = cv2.TrackerMOSSE_create()
AttributeError: module 'cv2.cv2' has no attribute 'TrackerMOSSE_create'

witch is wierd bechos i have downloaded all the librarys the guy in the video mentioned and i cant seem to be able to get rid of it. i now it means that a cirtone module or code is missing and i cant download an older version of this pls gelp and thx for reading

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Yatharth Shah said:

How did you install these modules? Did you pip install it?

the program PyCharm alows me to instal with a few clicks.I think the program is running the pip commands for me

image.thumb.png.ff2b867733a740bbeb45481bc7b0b9a1.png

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, gabrielcarvfer said:

sorry but i am not realy good with this stuff so wat do you think i shuld do if the trackers whore moved i mean how can i move them back

Link to comment
Share on other sites

Link to post
Share on other sites

On 1/26/2021 at 8:55 AM, Symbolls said:

sorry but i am not realy good with this stuff so wat do you think i shuld do if the trackers whore moved i mean how can i move them back

The code example is written for some older version of the opencv package so either try using one of the older versions or update the code example for current version. With luck it will be just changing imports.

Link to comment
Share on other sites

Link to post
Share on other sites

You may be using the wrong version of OpenCV. Check which version of the module your tutorial requires and install that one. Also don't install both. You should install only opencv-contrib-python, as that contains opencv-python already.

On 1/26/2021 at 8:55 AM, Symbolls said:

sorry but i am not realy good with this stuff so wat do you think i shuld do if the trackers whore moved i mean how can i move them back

For example where the code says "tracker = cv2.TrackerMOSSE_create()", you should now say "tracker = cv2.legacy.TrackerMOSSE_create()".

 

However, judging by "legacy" this could mean this functionality is outdated and will be removed. So either update the code to use the proper convention for the current version, or as I said above check which version the tutorial assumes and use that.

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×