Ask Your Question

MdK8's profile - activity

2015-08-11 09:17:31 -0600 asked a question OpenCV for iOS - Linking Libraries in Xcode

Hi,

as part of a team project I intend to implement obstacle detection for a robot using open cv. I am now at a point where I have functional code that runs on OS X and uses my laptop camera to detect obstacles approaching it. However the robot runs iOS (it is an iPad at heart) and thus requires me to build for iOS. Obviously the linker now doesn't accept the OS X library files, because of architecture mismatches. So far it is set up as follows:
1. /usr/local/lib added to Library Search Paths
2. /usr/local/include added to Header Search Paths
3. c++ language dialect changed to C++11
4. Libraries added to Other Linker Flags ( -lopencv_calib3d etc.)
5. Valid Architectures set to i386,x86_64

In order to perform the necessary modifications for iOS I first of all changed the valid architectures to armv7, armv7s, and arm64. Then I attempted to follow the instructions on OpenCV:Installation in iOS, asking me to execute the opencv/platforms/ios/build_framework.py script. This built a framework file which I added to my Xcode project via Build Phases -> Link Binary With Libraries. According to the python script's readme "The script builds OpenCV.framework for iOS. The built framework is universal, it can be used to build app and run it on either iOS simulator or real device." However when I try to build the product for iOS simulator (amongst others), I get uncountable Undefined symbols for architecture x86_64 linker errors. As far as I am aware there is nothing else to the installation instructions linked above though.

Am I missing something here? Adjusting header/library search paths to include either nothing or the OS X OpenCV library files from /usr/local/lib was to no avail. My intuition is that is has something to do with the folder build inside of the folder that contains the opencv2.framework file. The contents of build are the folders:
iPhoneOS-arm64
iPhoneOS-armv7
iPhoneOS-armv7s
iPhoneSimulator-i386
iPhoneSimulator-x86_64

These in turn are comprised of:
iPhoneOS-arm64 contents

Do I need to link any part of these folders into my project?

I am grateful for any advice.

Warm regards,
Mark

2015-07-27 11:22:42 -0600 received badge  Self-Learner (source)
2015-07-27 11:18:16 -0600 answered a question Issue Masking Input Image to findContours

Turns out that the constructor of Mat does not except numbers as arguments to the init_valueparameter, but requires use of Scalar()in order to work. As a consequence mask and black both had data nullpointers.

2015-07-27 03:35:26 -0600 commented question Issue Masking Input Image to findContours

Hi Matman, thank you for your reply! As far as I'm aware CV_8UC1 and CV_8U evaluate to the same type. In accordance with that knowledge changing the type did not help. black.create() also yielded the same errors. Anyway, I came up with a simpler code that now at least runs, but gives me a black image every iteration, regardless of the contents of mask. I now simply use setTo() to directly change the canny_output to avoid errors while copying. I'll attach the revised code to my initial post.

2015-07-25 11:21:08 -0600 received badge  Editor (source)
2015-07-25 10:19:47 -0600 asked a question Issue Masking Input Image to findContours

Hi,

I am currently implementing obstacle detection using the camera output of a robot's floor-directed video camera. Using canny edge detection as preprocessing I am able to efficiently find contours using findContours. Whenever I find sufficient amounts of contours I send out an obstacle warning. So far so good - code compiles and works using laptop camera. The last remaining issue is that the robot films its own body using the camera (i.e. its base and wheels) and I obviously do not consider them to be obstacles and would hence like to exclude them from contour finding. Seeing that neither canny nor findContours provide masking functionality, I decided to mask the input myself. So what I am currently doing is performing canny edge on the whole image and then overwriting the area to be ignored with zeroes (i.e. color black), before I pass the image to find contours. I do this using copyTo(). However findContours throws an "Unrecognized or unsupported array type in function cvGetMat" exception if my mask indicates to overwrite nothing, and copyTo() an "EXC_BAD_ACCESS" exception if my mask indicates to overwrite everything. I am unable to trace this error, as I assert type and size equality before using copyTo() and input and mask are static and therefore never empty. I would highly appreciate some feedback. I am guessing I am making a very fundamental mistake, as copyTo() should copy nothing given the code below (with the empty mask) and therefore the code should run just as before.

Any feedback is appreciated.

Warm regards,
Mark

int detectFloor(VideoCapture floorCam){

if( !floorCam.isOpened() ){
    cout << "Could not initialize capturing...\n";
    return 0;
}

Mat frame, image, gray, canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
RNG rng(12345);
Mat black(720,1280,CV_8U,0); // The black pixels I am copying later on
Mat mask(720,1280,CV_8U,0); // When to copy them (currently never) - I need to actually build the real mask

// Sensitivity of the contour detection
int thresh = 100;
// Sensitivity of obstacle detection i.e. number of contours needed to raise warning
int critical = 10;

for(;;){
    // Capture a 1280*720 frame
    floorCam >> frame;
    if( frame.empty() )
        break;
    frame.copyTo(image);

    // Convert image to gray for better accuracy during contour detection
    cvtColor(image, gray, COLOR_BGR2GRAY);
    // Blur image to remove disturbances
    blur( gray, gray, Size(3,3) );

    // Detect edges using canny to preprocess image for contour detection
    Canny( gray, canny_output, thresh, thresh*2, 3 );
    // Mask robot from canny_output by filling that area of the image with black
    // That way robot contours will be ignored during detection
    assert(black.size() == canny_output.size());
    assert(black.type() == canny_output.type());
    black.copyTo(canny_output, mask);
    // Find contours i.e. curves that join continuous points having same color or intensity
    findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
    // Contours indicate presence of alien entities
    // Therefore check if sufficient numbers of contours are present to raise alarm
    if (contours.size() > critical)
        cout << "Warning! Obstacle detected - " << contours.size() << " contours found." << endl;
}
return(0);
}

EDIT: Alternative approach using ... (more)