yihuang / pyccv

python binding to ccv library, written with cython.
MIT License
6 stars 0 forks source link

Object is not writeable #1

Open jeremy-rutman opened 8 years ago

jeremy-rutman commented 8 years ago

I tried the test.py which works ok (after I copy ccv.so to the cwd). Now I would like to try passing an image array to ccv functions so as a first test I try uncommenting the lines in test.py that use matrix.set_buf:

import sys
from ccv import PY_CCV_IO_GRAY, DenseMatrix, ClassifierCascade, detect_objects

matrix = DenseMatrix()

from PIL import Image
img = Image.open(sys.argv[1])
st=img.tostring()
matrix.set_buf(st, img.mode, img.size[0], img.size[1], PY_CCV_IO_GRAY)

However this runs into the following error:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    matrix.set_buf(st, img.mode, img.size[0], img.size[1], PY_CCV_IO_GRAY)
  File "ccv.pyx", line 70, in ccv.DenseMatrix.set_buf (ccv.c:1832)
    def set_buf(self, char[:] buf, mode, int rows, int cols, int convert=0):
  File "stringsource", line 614, in View.MemoryView.memoryview_cwrapper (ccv.c:8733)
  File "stringsource", line 321, in View.MemoryView.memoryview.__cinit__ (ccv.c:5279)
BufferError: Object is not writable.

What am I doing wrong here?

jeremy-rutman commented 8 years ago

ok if you wrap the string with bytearray then it won't crash , st=bytearray(img.tostring()) and then matrix.set_buf(st,...) however this method of matrix.set_buf does not give the same results as matrix.set_file() - any clues on how to get usable results from an array passed into set_buf?