Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofxCv, toOf, toCv, ofImage::saveImage and crash

$
0
0

@nkint wrote:

Hi
It's a while I'm not using OF and C++ and I'm a bit rusty.

I'm facing with a EXC_BAD_ACCESS (SIGSEGV) while saving an image, and don't understand exactly why.

What I'm trying to do:
- load image
- elaborate it with opencv
- save it

for loading and saving I'm trying to stay on standard OF routines (ofImage::loadImage and ofImage::saveImage) while elaboration with opencv. Don't know if it is the best way but I don't see anything wrong on it.

Saving causes the crash.

This is my code:

------------------------------------------------------------------------------------- cpp:

#include "SpikeSave.h"

using namespace cv;
using namespace ofxCv;

void SpikeSave::setup(){
    String fileinput = "/Users/alberto/Code/openframeworks/of_v0.8.0_osx_release/apps/myApps/photoSlice/bin/data/mimi/IMG_3791.JPG";
    original.loadImage(fileinput);

    Mat img = toCv(original);
    Mat out2;

    // some intense elaboration here..
    bitwise_not(img, out2);

    toOf(out2, original);
    original.update();
}

void SpikeSave::draw(){
    ofSetColor(255,255,255);
    original.draw(0, 0, 864, 576);
}

void SpikeSave::keyPressed(int key){
    if(key=='s') {
        string filename = ofGetTimestampString()+".png";
        std::cout << "save to "<< filename <<std::endl;

        std::cout << "original size: "<< original.width << " " << original.height <<std::endl;
        original.update();
        original.saveImage(filename);
    }
}

void SpikeSave::update(){}
void SpikeSave::keyReleased(int key){}
void SpikeSave::mouseMoved(int x, int y){}
void SpikeSave::mouseDragged(int x, int y, int button){}
void SpikeSave::mousePressed(int x, int y, int button){}
void SpikeSave::mouseReleased(int x, int y, int button){}
void SpikeSave::windowResized(int w, int h){}
void SpikeSave::gotMessage(ofMessage msg){}
void SpikeSave::exit(){}
void SpikeSave::dragEvent(ofDragInfo dragInfo){}

------------------------------------------------------------------------------------- h:

#pragma once

#include "ofMain.h"
#include "ofxCv.h"
#include "ofxUI.h"

class SpikeSave : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y);
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);
        void exit();

    private:
        ofImage original;
};

Just for information I'm on a mac os/x, compiling with Qtcreator, OF 0.8.0, opencv 2.3 (the one imported with ofxOpenCV)

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles