THIS IS MY CODE:
JavaScript
x
16
16
1
import cv2 as cv
2
import numpy as np
3
4
5
cap = cv.VideoCapture(0)
6
imgTarget = cv.imread('photosTargetImage.jpg') #bu resmimiz
7
Vid = cv.VideoCapture('photosvideo.mp4')
8
9
10
detection = False
11
frameCounter = 0
12
13
success, Video = Vid.read()
14
h,w,c = imgTarget.shape #burada resmimizin yüksekliğini, kalınlığını genişliğini falan alıyoruz.
15
Video = cv.resize(Video, (w, h))
16
Guys, this is the part of my code. I am trying to resize my image but ıt gives the following error:
error: OpenCV(4.0.1) C:ciopencv-suite_1573470242804workmodulesimgprocsrcresize.cpp:3784: error: (-215:Assertion failed) !ssize.empty() in function ‘cv::resize’
Do you have any suggestions to solve this?
Advertisement
Answer
If I’m not mistaken, you want to resize the video frames with the same size of imgTarget
You can solve with two-steps
-
- Check whether the video is opened
-
- If the video is opened then
resize
- If the video is opened then
First you should be checking whether your video can be opened
JavaScript
1
5
1
h,w,c = imgTarget.shape #burada resmimizin yüksekliğini, kalınlığını genişliğini falan alıyoruz.
2
3
while Vid.isOpened():
4
success, Video = Vid.read()
5
Now you need to check whether the current frame returns
JavaScript
1
6
1
h,w,c = imgTarget.shape #burada resmimizin yüksekliğini, kalınlığını genişliğini falan alıyoruz.
2
3
while Vid.isOpened():
4
success, Video = Vid.read()
5
if success:
6
Now resize
JavaScript
1
7
1
h,w,c = imgTarget.shape #burada resmimizin yüksekliğini, kalınlığını genişliğini falan alıyoruz.
2
3
while Vid.isOpened():
4
success, Video = Vid.read()
5
if success:
6
Video = cv.resize(Video, (w, h))
7
If you want to display you can use imshow
JavaScript
1
13
13
1
h,w,c = imgTarget.shape #burada resmimizin yüksekliğini, kalınlığını genişliğini falan alıyoruz.
2
3
while Vid.isOpened():
4
success, Video = Vid.read()
5
if success:
6
Video = cv.resize(Video, (w, h))
7
cv2.imshow("Video")
8
key = cv2.waitKey(1) & 0xFF
9
10
# if the `q` key was pressed, break from the loop
11
if key == ord("q"):
12
break
13
Make sure to release the cap
and Vid
variables at the end of the code.
JavaScript
1
16
16
1
h,w,c = imgTarget.shape #burada resmimizin yüksekliğini, kalınlığını genişliğini falan alıyoruz.
2
3
while Vid.isOpened():
4
success, Video = Vid.read()
5
if success:
6
Video = cv.resize(Video, (w, h))
7
cv2.imshow("Video")
8
key = cv2.waitKey(1) & 0xFF
9
10
# if the `q` key was pressed, break from the loop
11
if key == ord("q"):
12
break
13
14
Vid.release()
15
cap.release()
16