简体   繁体   中英

Signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr

I'm trying to do stitching on android. I used Surf algorithm to serve as finder and I got an error like "try enable OPENCV_ENABLED_NONFREE". I use C++ native code on Android Studio and do stitching in background. I solved the surf error but now, when I test this application on real device, I get this error:

错误

I did some research in another forum, and they say that the problem may be caused by a function that doesn't return the value it's supposed to return. Is there anyone who can help me please. This is the code:

private Handler handler = new Handler(new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        switch (message.what) {
            case HANDLER_START_STITCHING :
            {
                new Thread()
                {
                    public void run()
                    {
                        AsyncTask.execute(new Runnable() {
                            @Override
                            public void run() {
                                String[] source=getDirectoryFilelist("null");

                                final File resultDir = new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + File.separator + "viewwer");

                                // if (!resultDir.exists())
                                // resultDir.mkdir();

                                final String stitchingResultImagePath = new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath()) +"/result.jpg"; // + (ANGLE-90) + ".jpg";
                                if( NativePanorama.jniStitching(source, stitchingResultImagePath, STITCH_IMAGE_SCALE) == 0 )
                                {
                                    handler.sendMessage(handler.obtainMessage(HANDLER_SET_STITCHING_BUTTON_TEXT,"Stitching success"));

                                    File image = new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath());
                                    File result_90 =  new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/result90.jpg");
                                    File result_180 =  new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/result180.jpg");

                                    File result_270 =  new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/result270.jpg");
                                    File result_360 =  new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/result360.jpg");

                                    Log.d("GESTION_STITCHING", result_180.toString());

                                    /*if (ANGLE == 450) {
                                        handler.sendMessage(handler.obtainMessage(HANDLER_FINISH_STITCHING,"Stitching success"));
                                    }*/

                                    if (image.exists()) {
                                        File[] files = image.listFiles();
                                        for (int i=0;i<files.length; i++) {
                                            if (files[i].compareTo(result_90) == 0 || files[i].compareTo(result_180) == 0 || files[i].compareTo(result_270) == 0 || files[i].compareTo(result_360) == 0) {

                                            } else {
                                                 files[i].delete();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    handler.sendMessage(handler.obtainMessage(HANDLER_SET_STITCHING_BUTTON_TEXT,"Stitching error"));
                                }
                            }
                        });
                    }
                }.start();
                break;
            }

and the following is the native C++ code:

JNIEXPORT jint JNICALL Java_com_priscilla_viewwer_utils_NativePanorama_jniStitching(JNIEnv *env, jclass clazz, jobjectArray source, jstring result, jdouble scale) {

clock_t beginTime, endTime;
double timeSpent;
beginTime = clock();
//init jni call java method

int i = 0;
bool try_use_gpu = true;
vector<Mat> imgs;
Mat img;
Mat img_scaled;
Mat pano;
Mat pano_tocut;
Mat gray;

const char* result_name = env->GetStringUTFChars(result, JNI_FALSE);  //convert result
LOGE("result_name=%s",result_name);
LOGE("scale=%f",scale);
int imgCount = env->GetArrayLength(source); //img count
LOGE("source imgCount=%d",imgCount);
for(i=0;i<imgCount;i++)
{
    jstring jsource = (jstring)(env->GetObjectArrayElement(source, i));
    const char* source_name = env->GetStringUTFChars(jsource, JNI_FALSE);  //convert jsource
    LOGE("Add index %d source_name=:%s", i, source_name);
    img=imread(source_name);
    Size dsize = Size((int)(img.cols*scale),(int)(img.rows*scale));
    img_scaled = Mat(dsize,CV_32S);
    resize(img,img_scaled,dsize);
    imgs.push_back(img_scaled);
    env->ReleaseStringUTFChars(jsource, source_name);  //release convert jsource
}
img.release();

pano = stitchingImages(imgs);
for(i=0;i<imgs.size();i++)
{
    imgs[i].release();
}

//cut black edges
//LOGE("stitching success,cutting black....");
pano_tocut = pano;
cvtColor(pano_tocut, gray, CV_BGR2GRAY);
Rect startROI(0,0,gray.cols,gray.rows); // start as the source image - ROI is the complete SRC-Image
cropLargestPossibleROI(gray,pano_tocut,startROI);
gray.release();

imwrite(result_name, pano_tocut);
pano.release();
pano_tocut.release();
env->ReleaseStringUTFChars(result, result_name);  //release convert result
endTime = clock();
timeSpent = (double)(endTime - beginTime) / CLOCKS_PER_SEC;
LOGE("success,total cost time %f seconds",timeSpent);
// env->CallVoidMethod(clazz, javaMethodRef, timeSpent);
return 0;
}

I came cross this issues either, and I found it was violating strict aliasing .

cause by casting~

problem:

uint32_t i32 = *((uint32_t*)m_data);

solution:

uint32_t i32 = 0;
char* p = (char*)&i32;
for(int i =0;i < 4;i++)
{
    p[i] = m_data[i];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM