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 9256949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:05:48+00:00 2026-06-18T12:05:48+00:00

I am having a problem where some numpy arrays don’t convert to cvMat using

  • 0

I am having a problem where some numpy arrays don’t convert to cvMat using cv.fromarray(). It appears the problem occurs whenever the numpy array has been transposed.

import numpy as np
import cv

# This works fine:
b = np.arange(6).reshape(2,3).astype('float32')
B = cv.fromarray(b)
print(cv.GetSize(B))

# But this produces an error:
a = np.arange(6).reshape(3,2).astype('float32')
b = a.T
B = cv.fromarray(b)
print(cv.GetSize(B))

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test_err.py", line 17, in <module>
    B = cv.fromarray(b)
TypeError: cv.fromarray array can only accept arrays with contiguous data

Any suggestions? Many of my arrays have been transposed at some point so the error is coming up frequently.

I’m using Python2.7 on MacOS X Lion with NumPy 1.6.2 and OpenCV 2.4.2.1 installed from MacPorts.

  • 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-06-18T12:05:49+00:00Added an answer on June 18, 2026 at 12:05 pm

    You can check your arrays using the flags.contiguous attribute, and if they are not, make them be using copy():

    >>> a = np.arange(16).reshape(4,4)
    >>> a.flags.contiguous
    True
    >>> b = a.T
    >>> b.flags.contiguous
    False
    >>> b = b.copy()
    >>> b.flags.contiguous
    True
    

    When you ask for a transpose, numpy doesn’t actually transpose the data, only the strides used to access it, unless you specifically trigger a copy with copy().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problem with my Jquery. So, the problem is that whenever i
I'm having a problem using some of the XPaths given to me by Chrome.
I'm having some problem using multiple selectBooleanCheckBox in multiple DataTables in ui:repeat. Something like
I am having problem getting some datetime conversions. I am actually using django and
I'm having problem with understanding some of QList behavior. #include <QList> #include <iostream> using
I'm having some problem setting up an oauth provider with two-legged authentication. I'm using
I'm having a problem maybe an inexperience of using global variable which causes some
Im having some problem with a bit of JQuery code and I don't know
I'm having some problem with this code using the #as_json method. render json: channel.as_json({
I'm having some problem with validations for multiple fields, specifically with case-sensitive unique validations

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.