0

OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'warpPerspective'

Overload resolution failed:

  • src is not a numpy array, neither a scalar
  • Expected Ptr<cv::UMat> for argument 'src'
import numpy as np

img = cv2.VideoCapture(0)

while True:

    # Step 1: Define 4 corner points , use any photo editor like paint to get pixel location of the points
    pts1 = np.float32([[85,30],[150,30],[86,125],[150,125]])

    # Step 2: Define location of the points
    width, height = 250, 350 # getting required size by taking care of height & width ratio of card
    pts2 = np.float32([[0,0],[width,0],[0,height],[width,height]])

    # Step 3: Make matrix
    matrix = cv2.getPerspectiveTransform(pts1,pts2)

    # Get Output image based on the above matrix
    imgOutput = cv2.warpPerspective(img, matrix, (width, height))

    cv2.imshow("Image",img)
    cv2.imshow("Output", imgOutput)

    if cv2.waitKey(1) == ord('q'):
            break

img.release()
cv2.destroyAllWindows()```
  • Does this answer your question? [Pandas conditional creation of a series/dataframe column](https://stackoverflow.com/questions/19913659/pandas-conditional-creation-of-a-series-dataframe-column) – Talent Gramzrah Apr 08 '22 at 18:03
  • 1
    You are passing the video capture object to the function. You are supposed to get the frame input from the video and feed it as input – Jeru Luke Apr 08 '22 at 18:33
  • Within the `while` loop enter `ret, frame = img.read()`. Now pass `frame` as input to the warp function – Jeru Luke Apr 08 '22 at 18:36

1 Answers1

0

Why don't you pay attention @Jeru Luke. You're missing one extra cv2.cvtColor. I changed in line #24 with gray instead of img.

import cv2
import numpy as np

img = cv2.VideoCapture(0)

while img.isOpened():
    ret, frame = img.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Step 1: Define 4 corner points , use any photo editor like paint to get pixel location of the points
    pts1 = np.float32([[85,30],[150,30],[86,125],[150,125]])

    # Step 2: Define location of the points
    width, height = 250, 250 # getting required size by taking care of height & width ratio of card
    pts2 = np.float32([[0,0],[width,0],[0,height],[width,height]])

    # Step 3: Make matrix
    matrix = cv2.getPerspectiveTransform(pts1,pts2)

    # Get Output image based on the above matrix
    
    imgOutput = cv2.warpPerspective(gray, matrix, (width, height))

    cv2.imshow("Image", gray)
    cv2.imshow("Output", imgOutput)

    if cv2.waitKey(1) == ord('q'):
            break

img.release()
cv2.destroyAllWindows()

I'm using Raspberry pi4/8gb, linux 4.5.5, Bullseye v11.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19