I want to perform a double hysterisis thresholding. I pass the bitmap as a parameter, and then I threshold it to return it back to android. my native code is:
#include <jni.h>
#include <android/log.h>
#include <android/bitmap.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <inttypes.h>
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t alpha;
} argb;
JNIEXPORT void JNICALL Java_com_mypakage_MainActivity_Hysterisis
(JNIEnv *env, jobject obj, jobject bmp){
AndroidBitmapInfo infocolor;
void* pixelscolor;
int ret;
int y;
int x;
uint32_t *pixel;
if ((ret = AndroidBitmap_getInfo(env, bmp, &infocolor)) < 0) {
return;
}
if ((ret = AndroidBitmap_lockPixels(env, bmp, &pixelscolor)) < 0) {
}
pixel = (uint32_t *) pixelscolor;
uint32_t p,ac,bc,cc,dc,ec,fc,gc,hc;
bool again = true;
while (again) {
again=false;
for (y=1;y<=infocolor.height - 1;y++) {
for (x=1;x<infocolor.width -1;x++) {
p = (uint32_t) ( (*(pixel + x + (y ) * infocolor.stride)));
if (p == 0xFF888888) {
ac = (uint32_t) ( (*(pixel + x -1 + (y -1 ) * infocolor.stride)));
bc = (uint32_t) ( (*(pixel + x + (y -1 ) * infocolor.stride)));
cc = (uint32_t) ( (*(pixel + x +1 + (y -1 ) * infocolor.stride)));
dc = (uint32_t) ( (*(pixel + x +1 + (y ) * infocolor.stride)));
ec = (uint32_t) ( (*(pixel + x +1 + (y+1 ) * infocolor.stride)));
fc = (uint32_t) ( (*(pixel + x + (y +1 ) * infocolor.stride)));
fc = (uint32_t) ( (*(pixel + x -1 + (y +1 ) * infocolor.stride)));
fc = (uint32_t) ( (*(pixel + x -1 + (y ) * infocolor.stride)));
if (ac ==0xFFFFFFFF || bc ==0xFFFFFFFF || cc ==0xFFFFFFFF || dc ==0xFFFFFFFF
|| ec ==0xFFFFFFFF || fc ==0xFFFFFFFF || gc ==0xFFFFFFFF || hc ==0xFFFFFFFF) {
( (*(pixel + x + (y ) * infocolor.stride)))= 0xFFFFFFFF;
again=true;
}
}
}
}
}
for (y=1;y<=infocolor.height - 1;y++) {
for (x=1;x<infocolor.width -1;x++) {
p = (uint32_t) ( (*(pixel + x + (y ) * infocolor.stride)));
if (p == 0xFF888888) {
( (*(pixel + x + (y ) * infocolor.stride)))= 0xFF000000;
}
}
}
AndroidBitmap_unlockPixels(env, bmp);
}
My problem is that the app crashes with the following error:
A/libc(29191): Fatal signal 11 (SIGSEGV) at ...
Any help?
Aucun commentaire:
Enregistrer un commentaire