簡體   English   中英

信號 7 (SIGBUS),代碼 1 (BUS_ADRALN),故障地址

[英]Signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr

我正在嘗試在 android 上進行拼接。 我使用 Surf 算法作為查找器,但出現“嘗試啟用 OPENCV_ENABLED_NONFREE”之類的錯誤。 我在 Android Studio 上使用 C++ 本機代碼並在后台進行拼接。 我解決了沖浪錯誤,但現在,當我在真實設備上測試此應用程序時,我收到此錯誤:

錯誤

我在另一個論壇上做了一些研究,他們說問題可能是由 function 引起的,它沒有返回它應該返回的值。 請問有沒有人可以幫助我。 這是代碼:

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;
            }

以下是本機 C++ 代碼:

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;
}

我也遇到過這個問題,我發現它違反了嚴格的別名

鑄造造成的~

問題:

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

解決方案:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM