Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6477199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:55:09+00:00 2026-05-25T06:55:09+00:00

My platform is Mac OS X 10.6 and install python 2.7.2/opencv by homebrew. I

  • 0

My platform is Mac OS X 10.6 and install python 2.7.2/opencv by homebrew.
I want to use cv.filter2D to do Lanczos resampling, here is my code:

import cv

src = cv.imread('img.jpg')
dst = cv.CloneMat(src)
kernel = cv.CreateMat(7, 7, cv.CV_32FC1)

for i in range(-3, 4):
    for j in range(-3, 4):
        kernel[i+3, j+3] = L(i, 3) * L(j, 3)

cv.filter2D(src, dst, kernel)
cv.imshow(dst)

My problem is cv.filter2D.
If I use

cv.filter2D(src, dst, kernel) 

, which wrote in OpenCV Reference Manual, it will get error message.

Traceback (most recent call last):
  File "lanczos.py", line 27, in <module>
    cv.filter2D(src, dst, kernel)
TypeError: only length-1 arrays can be converted to Python scalars

Under python I type

cv.filter2D.__doc__

, it said the function prototype is

'filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) -> dst'

if I use

cv.filter2D(src, -1, kernel, dst)

instead, the error message become

Traceback (most recent call last):
  File "lanczos.py", line 27, in <module>
    cv.filter2D(src, 1 , kernel, dst)
TypeError: <unknown> is not a numpy array

seems no people encounter this problem before?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:55:10+00:00Added an answer on May 25, 2026 at 6:55 am

    what is the version of your opencv, my version is:

    >>> import cv2 as cv
    >>> cv.__version__
    '$Rev: 4557 $'
    

    I can use a ndarray as the kernel, and don’t need to create an empty array for the result, filter2D() will return a new ndarray.

    import cv2 as cv
    import numpy as np
    src = cv.imread('img.jpg')
    kernel = np.ones((7,7), dtype=np.float)/49.0
    dst = cv.filter2D(src, -1, kernel)
    cv.imwrite("result.jpg", dst)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to install matplotlib for graphing applications in Python on Mac OS X.
I was able to install and use IBM DB2 Express-C 9.5.2. beta in Mac
When considering a platform for a game, I've decided on multi-platform (Win/Lin/Mac) but can't
I'm writing a cross-platform C++ program using Qt and I want to package/embed a
I want to write a python script to convert PNG's into 2-page pdfs (i.e.
I need an advice for cross-platform engine/framework for desktop PC application development (Windows, MAC,
I tried to follow these instructions get OpenCV to compile on my MAC MINI,
I am trying to install MySQLdb python and am having trouble getting it to
I'm clearly missing something here. I'm trying to install the torquebox gems and am
I'm new with Haskell and have trouble with its package. I want to import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.