How could be diff(X) converted to OpenCV or Objective C? - objective-c

How could be differentiation implemented within XCode Objective C or OpenCV ? (diff(BWImage) in matlab that is http://www.mathworks.com/help/techdoc/ref/diff.html)

You don't need to implement it, it is already done, that's what cv::Sobel does. http://opencv.willowgarage.com/documentation/cpp/imgproc_image_filtering.html#cv-sobel

Related

how can I pass unsafemutablerawpointer as a C's pointer to objective c++?

I'm trying to integrate CoreML model into my app. The output is given by a MLMultiArray, but I want the data in it in order to generate an OpenCV matrix. There is a dataPointer property in MLMultiArray, which is a UnsafeMutableRawPointer. How can I pass it as a C's pointer so that I can directly use it to generate an OpenCV matrix?
Thanks in advance!
I found a solution. I don't need to pass the dataPointer as C's pointer from Swift to Objective-C++. I can just pass the whole MLMultiArray as long as I import in the obj-c++ file. And then I can directly use dataPointer to get a OpenCV Mat

How to call D functions from Objective C?

How could it be possible to call D functions from Objective C? Is such a bridge even possible?
D has limited Objective-C support already: https://dlang.org/spec/objc_interface.html
This thread explains how to do the same from C++: Calling a D function directly from C++
I guess it should not be difficult to do the same from Objective-C code.
Since Objective-C still has all the C stuff, they could call each others functions through the extern(C) interface too, reducing the problem to the solved issue of calling D functions from C.

Can clang or gcc convert Objective C code into plain C?

I'd like to convert Objective C code into plain C. I can do this by hand rather easily. For example this Objective C code:
[object method];
could be converted to something like:
SEL method = sel_registerName("method");
objc_msgSend(object, method);
However this is kind of tedious, especially for larger files. It seems clang should be able to generate this C code pretty easily. Is there a way I can convince it to do so?
Short answer: No.
Longer answer: clang supports -rewrite-objc, but you are almost certainly not going to like the results.

Can we write Objective-C code in C style syntax?

I am little confused finding C style syntax in an Objective-C project (for example below syntax is not how method are defined in Objective-C, by the book). I am clear that this works since the code I have compiles without errors - but I am not sure how and why, this code is regular Objective-C .h,.m files. Can someone explain how this fits in?
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//use of round brackets
void drawLinearGradient(CGContextRef context, CGRect rect, CGColorRef startColor,
CGColorRef endColor);
// C style syntax for passing params
Also this is very specific around the Core Graphics code that I have seen so far, is it allowed to write regular Objective-C methods like this also or only files with CG code...?
Objective-C is just a superset of C, in the same way as C++. (Both were originally implemented as preprocessors that convert the code to straight C code.) Objective-C method calls are translated to calls to the C function objc_msgSend() (and its variants) and it's possible (though tedious) to call it directly.
The gory details are spelled out here:
https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html
Core Graphics is a C API, not Objective-C. Since Objective-C is a superset of C, any valid C code will compile just fine in .m files.
Objective-C is a superset of C, so you can define plain old C functions in a .m file, and you can call plain old C functions in a .m file using the normal C syntax.
The CGColorSpaceCreateDeviceRGB function is a plain old C function. It is part of the Core Graphics framework (also known as Quartz 2D), which has a pure C API - the API only uses plain C, not Objective-C.
You cannot define Objective-C object methods using plain old C function syntax - you must use Objective-C method syntax. And you should not try to send messages to Objective-C objects using plain old C syntax - you should use the Objective-C message sending syntax (the square brackets).
objc supports standard C that why you find c code in objc project.
As for the framework provided by Apple, if it has coreprefix,like CG standing for core graphic, it usually means it is written in C.

How would I combine C and Objective-C in the same file?

I'm trying to make a Lua compiler for Mac OSX with an interface written in Objective-C and the Lua source code written in C.
You already are combining C and Objective C. No extra effort is needed.
Objective-C is a proper superset of C. Any C you write in an Objective-C file is perfectly valid.