Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I save cvMat in CoreData on iOS?
    primarykey
    data
    text
    <p>I am using CoreData in my project. I can save UIImage by using UIImageToDataTransformer class in my project. Also I am using opencv library and I need to save some cvMat struct (they are structs, right?). I have read some posts about transformable but still cant figure out how to save it in coredata and fetch it back. </p> <p>I have one entity called "Human" and it has a attribute called ProjVal and its type is transformable which holds data of cvMat. </p> <p>What should my next step be?</p> <p>Below its the transformer class for UIImage but how can I transform cvMat's data? Thank for your advices.</p> <pre><code>#import "UIImageToDataTransformer.h" @implementation UIImageToDataTransformer + (BOOL)allowsReverseTransformation { return YES; } + (Class)transformedValueClass { return [NSData class]; } - (id)transformedValue:(id)value { return UIImagePNGRepresentation(value); } - (id)reverseTransformedValue:(id)value { return [[[UIImage alloc] initWithData:value] autorelease]; } @end </code></pre> <p><strong>Edit:</strong> Is it a better way to use its type as Binary Data type instead Transformable type? Im using auto-created classes for my entities.</p> <p>I use this code while saving</p> <pre><code>CvMat *mat = cvCreateMat(3, 3, CV_32FC1); for (int i=0; i&lt;9; i++) { mat-&gt;data.fl[i] = 1.0f; } NSData *projValData = [[NSData alloc] initWithBytes:&amp;mat length:sizeof(mat)]; human.projVal = projValData; </code></pre> <p>and while reading it back:</p> <pre><code>CvMat *mat; NSData *data = [[humansArray objectAtIndex:0] projVal]; memcpy(&amp;mat,[data bytes],[data length]); if (mat) { NSLog(@"if mat works"); for (int i=0; i&lt;9; i++) { NSLog(@"%f",mat-&gt;data.fl[i]); } } </code></pre> <p>it doesnt work well and crashed in for loop. Where is my mistake?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload