Ask Your Question

hernancrespo's profile - activity

2021-06-07 09:38:55 -0500 received badge  Famous Question (source)
2021-06-07 09:38:55 -0500 received badge  Notable Question (source)
2021-06-07 09:38:55 -0500 received badge  Popular Question (source)
2021-04-20 20:52:45 -0500 received badge  Famous Question (source)
2020-11-09 10:16:51 -0500 marked best answer How to use CV_FOURCC in version 4.1.0?

Hi, i am new with openCV. i'm trying to paste a code snippet from old versions. But i get lots of error.

 VideoWriter parlakVideo("videoParlak.avi", CV_FOURCC(‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);
VideoWriter karanlikVideo("videoKaranlik.avi", CV_FOURCC(‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);

here is my try:

VideoWriter parlakVideo("video.wmv", VideoWriter::fourcc ((‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);
VideoWriter karanlikVideo("video.wmv", VideoWriter::fourcc((‘M’, ‘P’, ‘4’, ‘2’), 20, boyut, true);
2020-11-09 10:16:46 -0500 received badge  Notable Question (source)
2020-06-07 08:52:23 -0500 received badge  Popular Question (source)
2020-05-21 05:11:40 -0500 marked best answer [Solved]cv2.cv2' has no attribute 'Tracker_create error

Hi I want to use OpenCV's trackers. I see this error

    tracker = cv2.Tracker_create(tracker_type)
AttributeError: module 'cv2.cv2' has no attribute 'Tracker_create'

I uninstalled opencv-python first, and then opencv-contrib-pythn.(I removed both of them completely), and reinstalled opencv-contrib-python (It's version is 4.2.0.34). Why do I see this error?

This is my implementation

import cv2
import sys

(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')

if __name__ == '__main__' :

# Set up tracker.
# Instead of MIL, you can also use

tracker_types = ['BOOSTING', 'MIL','KCF', 'TLD', 'MEDIANFLOW', 'GOTURN', 'MOSSE', 'CSRT']
tracker_type = tracker_types[0]

if int(minor_ver) < 3:

    tracker = cv2.Tracker_create(tracker_type)
else:
    if tracker_type == 'BOOSTING':
        tracker = cv2.TrackerBoosting_create()
    if tracker_type == 'MIL':
        tracker = cv2.TrackerMIL_create()
    if tracker_type == 'KCF':
        tracker = cv2.TrackerKCF_create()
    if tracker_type == 'TLD':
        tracker = cv2.TrackerTLD_create()
    if tracker_type == 'MEDIANFLOW':
        tracker = cv2.TrackerMedianFlow_create()
    if tracker_type == 'GOTURN':
        tracker = cv2.TrackerGOTURN_create()
    if tracker_type == 'MOSSE':
        tracker = cv2.TrackerMOSSE_create()
    if tracker_type == "CSRT":
        tracker = cv2.TrackerCSRT_create()

# Read video
video = cv2.VideoCapture(0)

# Exit if video not opened.
if not video.isOpened():
    print ("Could not open video")
    sys.exit()

# Read first frame.
ok, frame = video.read()
if not ok:
    print ('Cannot read video file')
    sys.exit()

# Define an initial bounding box
bbox = (287, 23, 86, 320)

# Uncomment the line below to select a different bounding box
bbox = cv2.selectROI(frame, False)

# Initialize tracker with first frame and bounding box
ok = tracker.init(frame, bbox)

while True:
    # Read a new frame
    ok, frame = video.read()
    if not ok:
        break

    # Start timer
    timer = cv2.getTickCount()

    # Update tracker
    ok, bbox = tracker.update(frame)

    # Calculate Frames per second (FPS)
    fps = cv2.getTickFrequency() / (cv2.getTickCount() - 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]))
        cv2.rectangle(frame, p1, p2, (255,0,0), 2, 1)
    else :
        # Tracking failure
        cv2.putText(frame, "Tracking failure detected", (100,80), cv2.FONT_HERSHEY_SIMPLEX, 0.75,(0,0,255),2)

    # Display tracker type on frame
    cv2.putText(frame, tracker_type + " Tracker", (100,20), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50),2);

    # Display FPS on frame
    cv2.putText(frame, "FPS : " + str(int(fps)), (100,50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2);

    # Display result
    cv2.imshow("Tracking", frame)

    # Exit if ESC pressed
    k = cv2.waitKey(1) & 0xff
    if k == 27 : break
2020-05-20 09:24:34 -0500 asked a question [Solved]cv2.cv2' has no attribute 'Tracker_create error

cv2.cv2' has no attribute 'Tracker_create error Hi I want to use OpenCV's trackers. I see this error tracker = cv

2020-05-20 05:01:23 -0500 marked best answer How to write first N images of video frames

Hi, I want to write a video from a frame file. Frames folder is this: image description

This is my result:

import cv2
import numpy as np
import glob
j=0
img_array = []
for filename in glob.glob('/content/drive/My Drive/M-30-HD/M-30-HD/*.jpg'): #I work on Google Colab
    img = cv2.imread(filename)
    height, width, layers = img.shape
    size = (width,height)

    print(j)
    j=j+1

    img_array.append(img)
    if(j==3000):
      break


out = cv2.VideoWriter('m30hd.mp4',cv2.VideoWriter_fourcc(*'MP4V'), 24, size)

for i in range(len(img_array)):
    out.write(img_array[i])
    print(i)
out.release()
2020-05-19 22:08:37 -0500 commented answer How to write first N images of video frames

I see this error Traceback (most recent call last): File "videoya_cevirme.py", line 27, in <module> frames

2020-05-19 19:56:13 -0500 edited question How to write first N images of video frames

How to write first N images of video frames Hi, I want to write a video from a frame file. Frames folder is this: This

2020-05-19 19:55:01 -0500 asked a question How to write first N images of video frames

How to write first N images of video frames Hi, I want to write a video from a frame file. Frames folder is this: This

2020-05-17 08:23:37 -0500 commented question Problem with writing video

Thanks a lot!!

2020-05-17 08:23:31 -0500 edited question Problem with writing video

Problem with writing video Hi, I try to crop a polygonal from video and write it. My cropping operation is successful.

2020-05-16 19:27:02 -0500 asked a question Problem with writing video

Problem with writing video Hi, I try to crop a polygonal from video and write it. My cropping operation is successful.

2020-04-19 07:33:53 -0500 commented question Trouble with writing video

Sorry, what do you mean by condition block?

2020-04-19 07:33:41 -0500 commented question Trouble with writing video

What do you mean by condition block?

2020-04-19 07:18:01 -0500 commented question Trouble with writing video

What do you mean by condition block?

2020-04-18 16:49:44 -0500 edited question Trouble with writing video

Trouble with writing video Hey, I want to create a video from images. Size of images are same. I create video using im

2020-04-18 16:48:01 -0500 edited question Trouble with writing video

Trouble with writing video Hey, I want to create a video from images. Size of images are same. I create video using im

2020-04-18 16:47:14 -0500 edited question Trouble with writing video

Trouble with writing video Hey, I want to create a video from images. Size of images are same. I create video using im

2020-04-18 16:44:42 -0500 asked a question Trouble with writing video

Trouble with writing video Hey, I want to create a video from images. Size of images are same. I create video using im

2020-04-13 14:58:36 -0500 commented question cv2.imshow() doesn't work when I remove cv2.watKey(0) after it

It works, thanks

2020-04-13 09:02:10 -0500 commented question cv2.imshow() doesn't work when I remove cv2.watKey(0) after it

But i need to run the video

2020-04-13 08:34:39 -0500 asked a question cv2.imshow() doesn't work when I remove cv2.watKey(0) after it

cv2.imshow() doesn't work when I remove cv2.watKey(0) after it Hi, I've been trying to use a deep learning model. I'm t

2020-04-06 04:01:39 -0500 received badge  Supporter (source)
2020-04-06 04:01:38 -0500 marked best answer How to use FPS module

Hi, First I've created a video using

import cv2
import numpy as np
import glob

img_array = []
for filename in glob.glob('C:/Users/mustafa/Downloads/highway/highway/input/*.jpg'):
    img = cv2.imread(filename)
    height, width, layers = img.shape
    size = (width,height)
    img_array.append(img)

out = cv2.VideoWriter('project.mp4',cv2.VideoWriter_fourcc(*'DIVX'), 24, size)

for i in range(len(img_array)):
    out.write(img_array[i])
out.release()

As you see, I set FPS of video as 24.

Secondly, when I try to use FPS module to measure FPS of video that I've created.

from imutils.video import FPS
import cv2
import numpy as np

cap = cv2.VideoCapture('p.mp4')
fps = FPS().start()

if (cap.isOpened()== False): 
  print("Error opening video stream or file")

while(cap.isOpened()):

  ret, frame = cap.read()
  if ret == True:

    cv2.imshow('Frame',frame)
    fps.update()

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

  else: 
    break
cap.release()
fps.stop()
print("[INFO] elapsed time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
cv2.destroyAllWindows()

I see this output:

[INFO] approx. FPS: 38.06
[INFO] elapsed time: 44.67

Also the length of original video is 70 seconds. Why I see different results?

2020-04-06 04:01:21 -0500 marked best answer 'NoneType' object is not subscriptable error after read some fames

I've been trying to read a video (format of videos is mp4) and do some operations in every 30th frame. Firstly, It works OK. But after some frames, I see this error:

File "C:\Users\mustafa\Desktop\vidoe_deneme\opencv_object_tracker.py", line 22, in <module>
    frame = frame[:, :, ::-1]
TypeError: 'NoneType' object is not subscriptable

I see this error on every video I've tried (Not only on a one video). What is the problem?

import cv2
from imutils.video import VideoStream
from imutils.video import FPS

cap = cv2.VideoCapture('k.mp4')
totalFrames = 0
# start the frames per second throughput estimator
fps = FPS().start()

print('before video')
# loop over frames from the video stream
while cap.isOpened():
    ret,frame = cap.read()

    frame = frame[:, :, ::-1]
    h, w = frame.shape[:2]
    rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    if totalFrames % 30 == 0:

        cv2.imshow("Frame", rgb)
    key = cv2.waitKey(1) & 0xFF
    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break
    totalFrames += 1
    fps.update()
# stop the timer and display FPS information
fps.stop()
print("[INFO] elapsed time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
cv2.destroyAllWindows()

Error

2020-04-05 16:05:50 -0500 edited question How to use FPS module

How to use FPS module Hi, First I've created a video using import cv2 import numpy as np import glob img_array = [] fo

2020-04-05 16:04:48 -0500 asked a question How to use FPS module

How to use FPS module Hi, First I've created a video using import cv2 import numpy as np import glob img_array = [] fo

2020-04-05 15:56:38 -0500 commented question 'NoneType' object is not subscriptable error after read some fames

I've tried. I see same error on the last frame of the video.

2020-04-05 10:13:08 -0500 commented question 'NoneType' object is not subscriptable error after read some fames

@supra56 It doesn't finish. Error throws out before the end frame

2020-04-05 05:52:25 -0500 edited question 'NoneType' object is not subscriptable error after read some fames

'NoneType' object is not subscriptable error after read some fames I've been trying to read a video (format of videos is

2020-04-05 05:47:24 -0500 asked a question 'NoneType' object is not subscriptable error after read some fames

'NoneType' object is not subscriptable error after read some fames I've been trying to read a video and do some operatio

2020-04-04 03:35:17 -0500 asked a question How to read every Nth frame in a video

How to read every Nth frame in a video Hi, I've been trying to read every Nth frame in a video (to improve performance).

2020-02-02 05:22:43 -0500 asked a question Should destroyAllWindows and release functions be used in Python?

Should destroyAllWindows and release functions be used in Python? Hi, i wrote a simple script to read frames from webcam

2020-02-01 12:36:58 -0500 commented question Mean of a frame always change?

I mean, there is just day light not any external source. dst = cv.cvtColor(frame,cv.COLOR_RGBA2GRAY) dst = dst &

2020-02-01 12:05:05 -0500 commented question Mean of a frame always change?

It is around %0.1. There is no any light source

2020-02-01 09:11:48 -0500 asked a question Mean of a frame always change?

Mean of a frame always change? Hi everyone, i read frames from webcam and print mean of 3-channels of frame. import cv

2020-01-31 05:56:10 -0500 commented question Captured frame always change

@berak i edited there (i posted that part wrong). so, still i see same problem

2020-01-31 05:55:01 -0500 commented question Captured frame always change

@LBerger i mean, area of contours are always changing. I am just using a webcam not sensor.

2020-01-31 05:53:12 -0500 edited question Captured frame always change

Captured frame always change Hi everyone, i am capturing a frame from webcam and processing that frame (finding size of

2020-01-31 05:52:00 -0500 commented question Captured frame always change

@supra56 i couldn't understand.. should i move it outside from for loop

2020-01-31 05:48:20 -0500 edited question Captured frame always change

Captured frame always change Hi everyone, i am capturing a frame from webcam and processing that frame (finding size of

2020-01-30 16:17:43 -0500 asked a question Captured frame always change

Captured frame always change Hi everyone, i am capturing a frame from webcam and processing that frame (finding size of