Illegal :UTF-8 character starting at position CFFI/LISP ?

Discussion of Common Lisp
Post Reply
joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Illegal :UTF-8 character starting at position CFFI/LISP ?

Post by joeish80829 » Fri Oct 18, 2013 12:56 pm

Im refferring to this OpenCV function on this post

Code: Select all

IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
I'm tring to get the c functionality where i can access the imageData struct member of IplImage with the below statement (more info here http://docs.opencv.org/modules/core/doc ... i#iplimage)

Code: Select all

IplImage* converted_image= cvLoadImage("c:\\box_in_scene.png",0):converted_image->imageData

when i try with this

Code: Select all

(dp converted-image (Load-image "/home/w/Documents/opencv-

2.4.6.1/samples/c/box_in_scene.png" 0))


(cffi:with-foreign-slots ((image-data)
converted-image (:struct ipl-image))
(cffi:foreign-string-to-lisp image-data))
I get the post title error message. I also get message when i try to setf IMAGE-DATA to another variable or list it .....i get same thing with foreign-slot-value

here is sampling of the more than 6 pages of converted_image->imageData that was cout'ed in C

Code: Select all

P1']}stqouqwruM/./22330/00+1)/+%+8S~sx{zzx|x~|x~y{~Y(&&''()+,%(%$%!  $l~

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Illegal :UTF-8 character starting at position CFFI/LISP

Post by nuntius » Sun Oct 20, 2013 9:26 pm

It looks your lisp impl is trying to parse the image into a string of UTF-8 characters.
Inevitably, some pixel doesn't parse correctly...
Pixels should stay as an array of bytes.

I suspect this function is the problem: cffi:foreign-string-to-lisp

pjstirling
Posts: 166
Joined: Sun Nov 28, 2010 4:21 pm

Re: Illegal :UTF-8 character starting at position CFFI/LISP

Post by pjstirling » Tue Oct 22, 2013 6:16 am

In some languages (c/php and python 2) byte arrays are indistinguishable from strings, common-lisp isn't like that. You want to make the IMAGE-DATA an array of bytes in your foreign data defs (which you should have inserted here as well :)), and then you can use CFFI:MEM-AREF to access the data as bytes.

joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Re: Illegal :UTF-8 character starting at position CFFI/LISP

Post by joeish80829 » Tue Oct 22, 2013 3:57 pm

here is my defcstruct for ipl-image which contains image-data....it works well as is so far can you help me covert the image-data pointer to an array of bytes like you suggested ....am new to opencv's advanced topics :)

Code: Select all

(cffi:defcstruct ipl-image
	(n-size :int)
	(id :int)
	(n-channels :int)
	(alpha-channel :int)
	(depth :int)
	(color-model :int) ;;Ignored by OpenCV - was :pointer, changed to :int so the struct values would match OpenCV's
	(channel-seq :int) ;;Ignored by OpenCV - was :pointer, changed to :int so the struct values would match OpenCV's
	(data-order :int)
	(origin :int)
	(align :int)
	(width :int)
	(height :int)
	(roi :pointer)
	(mask-roi :pointer)
	(image-id :pointer)
	(tile-info :pointer)
	(image-size :int)
	(image-data :string)
	(width-step :int)
	(border-mode :pointer)
	(border-const :pointer)
	(image-data-origin :string))

Post Reply