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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:28:16+00:00 2026-06-04T13:28:16+00:00

Apologies for the length of the post… I am using cython to wrap some

  • 0

Apologies for the length of the post…

I am using cython to wrap some cpp code for image processing.

On return of my processed image which is in 32-bit ARGB mode – i.e. a 32-bit uint where r = (buff[0] >> 16) & 0xFF; g = (buff[0] >> 8) & 0xFF; g = buff[0] & 0xFF, I read the data into a ndarray using a python object as suggested in the manual here: http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html using the following class:

cdef class DataPointer:
    cdef void* data_ptr
    cdef int size

    cdef set_data(self, int size, void* data_ptr):
        self.size = size
        self.data_ptr = data_ptr

    def __array__(self):
        return np.PyArray_SimpleNewFromData(2, [self.size,4], np.NPY_UINT8, self.data_ptr)

and the following calls:

    cdef np.ndarray image

    data = DataPointer()
    data.set_data(height*width, <void*>im_buff)

    image = np.array(data, copy=False)
    image.base = <PyObject*> data
    Py_INCREF(data)

This gives me an array where each row is seperate ARGB values and so has shape (height*width, 4). They look like this:

[ 67 115 138   1]

Where these values correspond to B G R A.

Now if I go ahead and do

original = np.delete(image, 3, 1).reshape((height, width, 3)
cv2.imshow('out', original)

It works fine, however the RGB values are reversed as BGR and so the image looks a funny colour.

However when I try to flip the values like so:

original = np.fliplr(np.delete(image, 3, 1)).reshape((height, width, 3))
print original [0, :3]
cv2.imshow('out', original)

I get the following correct RGB values printed but the error message from cv2.imshow()

[[138 115  67]
[138 114  68]
[136 110  64]]
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /Users/Tom/Desktop/OpenCV-2.4.0/modules/core/src/array.cpp, line 2482

Any idea why??

  • 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-04T13:28:17+00:00Added an answer on June 4, 2026 at 1:28 pm

    It fails because of bug in OpenCV: http://code.opencv.org/issues/1393

    You should be able to workaround this issue by multiplying flipped matrix by 1:

    original = original * 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

G'Day, Apologies for the length of the post, however the code is necessary. I
In the following example (apologies for the length) I have tried to isolate some
I'm compiling using Code::Blocks on Windows 7 using the MinGW compiler (which I can
I have written some code which produces simple animations based on cycling through a
Apologies for the length of this post, but I think the background is necessary
Firstly apologises for the length of code but I wanted to show it all.
I apologize if this code looks a bit like a mess (considering the length);
First let me apologize a bit for the length of this post, it's mostly
Apologies in advance for the length of this question! I have a data structure
First up, apologies for the length of this question! I have a page with

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.