Ask Your Question
0

I am trying to executing OpenCV application executable in riscv linux but i am getting error "terminate called after throwing an instance of 'cv::Exception'"

asked 2018-07-23 01:19:52 -0600

updated 2018-07-30 06:33:55 -0600

Eduardo gravatar image

I have cross complied OpenCV library statically for riscv architecture and successfully compiled OpenCV application (redEyeRemoval).After that i have added compiled object file and images to riscv-linux root file system.now i am trying to executing output object file from root file system.now i am getting error.

Command for cross compiling OpenCV library statically :--

$ cmake -DCMAKE_TOOLCHAIN_FILE=../riscv.toolchain.cmake ../../.. -DWITH_PNG=OFF -DWITH_OPENEXR=OFF -DBUILD_OPENEXR=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_EXE_LINKER_FLAGS="-static"

Makefile for cross compiling OpenCV appliction (redEyeRemoval) :--

CXX =riscv64-unknown-linux-gnu-g++

CXXFLAGS += -c -Wall $(shell pkg-config --cflags --libs --static /home/billa/Downloads/opencv-3.4.2/platforms/linux/riscv_build/install/lib/pkgconfig/opencv.pc) LDFLAGS += $(shell pkg-config --cflags --libs --static /home/billa/Downloads/opencv-3.4.2/platforms/linux/riscv_build/install/lib/pkgconfig/opencv.pc)

all:removeRedEyes

removeRedEyes: removeRedEyes.o; $(CXX) $< -o $@ $(LDFLAGS) -static

%.o: %.cpp; $(CXX) $< -o $@ $(CXXFLAGS) -static

clean: ; rm -f removeRedEyes.o removeRedEyes

Error :--

# /opencv/red/removeRedEyes
/opencv/red/removeRedEyes
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.2) /home/billa/Downloads/opencv-3.4.2/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'
Aborted

RedEyeRemoval.cpp code :

enter code here

/* Copyright 2017 by Satya Mallick ( Big Vision LLC ) http://www.learnopencv.com */

#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;


void fillHoles(Mat &mask)
{
    /* 
     This hole filling algorithm is decribed in this post
     https://www.learnopencv.com/filling-holes-in-an-image-using-opencv-python-c/
     */

    Mat maskFloodfill = mask.clone();
    floodFill(maskFloodfill, cv::Point(0,0), Scalar(255));
    Mat mask2;
    bitwise_not(maskFloodfill, mask2);
    mask = (mask2 | mask);

}

int main(int argc, char** argv )
{
    // Read image
    Mat img = imread("red_eyes2.jpg",CV_LOAD_IMAGE_COLOR);

    // Output image
    Mat imgOut = img.clone();

    // Load HAAR cascade
    CascadeClassifier eyesCascade("haarcascade_eye.xml");

    // Detect eyes
    std::vector<Rect> eyes;
    eyesCascade.detectMultiScale( img, eyes, 1.3, 4, 0 |CASCADE_SCALE_IMAGE, Size(100, 100) );


    // For every detected eye
    for( size_t i = 0; i < eyes.size(); i++ )
    {

        // Extract eye from the image.
        Mat eye = img(eyes[i]);

        // Split eye image into 3 channels.
        vector<Mat>bgr(3);
        split(eye,bgr);

        // Simple red eye detector
        Mat mask = (bgr[2] > 150) & (bgr[2] > ( bgr[1] + bgr[0] ));

        // Clean mask -- 1) File holes 2) Dilate (expand) mask
        fillHoles(mask);
        dilate(mask, mask, Mat(), Point(-1, -1), 3, 1, 1);



        // Calculate the mean channel by averaging
        // the green and blue channels

        Mat mean = (bgr[0]+bgr[1])/2;
        mean.copyTo(bgr[2], mask);
        mean.copyTo(bgr[0], mask);
        mean.copyTo(bgr[1], mask);

        // Merge channels
        Mat eyeOut;
        cv::merge(bgr,eyeOut);

        // Copy the fixed eye to the output image.
        eyeOut.copyTo(imgOut(eyes[i]));

    }

    // Display Result
    imshow("Red Eyes", img);
    imshow("Red Eyes Removed", imgOut);
    waitKey(0);

}
edit retag flag offensive close merge delete

Comments

It seems that your cascade file is empty. Have you use this code to load cascade file ?

LBerger gravatar imageLBerger ( 2018-07-23 02:42:53 -0600 )edit

no i didn't used.can u tell me how to use and where.

Thanks for reply

Billa Surendra gravatar imageBilla Surendra ( 2018-07-23 03:12:46 -0600 )edit

Can you post your code in your question (use edit button)?

LBerger gravatar imageLBerger ( 2018-07-23 03:15:31 -0600 )edit
1

please go through my code once i have posted code

Billa Surendra gravatar imageBilla Surendra ( 2018-07-23 03:44:09 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-07-23 03:49:04 -0600

LBerger gravatar image

updated 2018-07-23 04:19:42 -0600

When you read data from disk you must check result :

// Read image
Mat img = imread("red_eyes2.jpg",CV_LOAD_IMAGE_COLOR);
if (img.empty())
{
    cout<<" File is empty : check file path\n";
   exit(-1);
}
// Output image
Mat imgOut = img.clone();

// Load HAAR cascade
CascadeClassifier eyesCascade;
if( !eyesCascade.load( "haarcascade_eye.xml" ) )
{
    cout << "--(!)Error loading eyes cascade. Check file path\n";
    return -1;
};
edit flag offensive delete link more

Comments

I have modified some code in RedEyeRemoval.cpp program as you said above.now i am getting error like can you give solution for this please

Error : removeRedEyes.cpp: In function 'int main(int, char)': removeRedEyes.cpp:43:10: error: 'eyes_cascade' was not declared in this scope if( !eyes_cascade.load( "haarcascade_eye.xml" ) ) ^~~~~~~~~~~~ removeRedEyes.cpp:43:10: note: suggested alternative: 'eyesCascade' if( !eyes_cascade.load( "haarcascade_eye.xml" ) ) ^~~~~~~~~~~~ eyesCascade Makefile:10: recipe for target 'removeRedEyes.o' failed make: * [removeRedEyes.o] Error 1

Billa Surendra gravatar imageBilla Surendra ( 2018-07-23 04:18:05 -0600 )edit

yes,RemoveRedEyes.cpp is cross compiled successfully and again i am added compiled object file and image into riscv-linux root file system.now i am getting another error.

Error:--

BusyBox v1.26.2 (2018-06-27 09:49:37 IST) built-in shell (ash)

/opencv/red/removeRedEyes

/opencv/red/removeRedEyes File is empty : check file path

Thanks in advance..

Billa Surendra gravatar imageBilla Surendra ( 2018-07-23 04:44:40 -0600 )edit

Yes you must check file path : where is haarcascade_eye.xml on your disk? give full path of haarcascade_eye.xml in your code or copy haarcascade_eye.xml where is your executable file.

LBerger gravatar imageLBerger ( 2018-07-23 04:47:14 -0600 )edit

After cross compiling RemoveRedEyes.cpp for riscv and i am copying compiled object file,haarcascade_eye.xml,and one sample image into riscv-linux root file system.and i am trying to executing compiled object file from riscv-linux root file system.now i am getting error like this

Error :--

BusyBox v1.26.2 (2018-06-27 09:49:37 IST) built-in shell (ash)

/opencv/red/removeRedEyes

/opencv/red/removeRedEyes File is empty : check file path

Billa Surendra gravatar imageBilla Surendra ( 2018-07-23 05:18:56 -0600 )edit

Thanks for your best support..my problem solved now..

Billa Surendra gravatar imageBilla Surendra ( 2018-08-07 04:46:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-23 01:19:52 -0600

Seen: 2,875 times

Last updated: Jul 23 '18