I am reading a RGB565 Image from Java and passing as a bytearray to JNI function. then converting to FastCV Img using this function
but when I apply the threshold I get
Assertion failed @fcvFilterThresholdu8: src && dst && (signed)threshold >= 0
void convertToFastCV(JNIEnv *env,jbyteArray source, uint8_t *destination,jint width, jint height){LOGD("Convert to FastCV Obj");jbyte* jimgData = NULL;jboolean isCopy = 0;LOGD("Reading");//RGB 565 Input ImagejimgData = env->GetByteArrayElements(source, &isCopy);destination = (uint8_t*)jimgData;// Buffer to place image data if camera callback data is not aligneduint8_t* alignedImgBuf;LOGD("Checking aligned");// Check if camera image data is not aligned.if( (int)jimgData & 0xF ){// Allocate buffer for aligned data if necessary.if(alignedImgBuf == NULL ){alignedImgBuf = (uint8_t*)fcvMemAlloc( width*height*3/2, 16 );}LOGD("Aligning");memcpy( alignedImgBuf, jimgData, width*height*3/2 );destination = alignedImgBuf;}LOGD("Done");}JNIEXPORT jlong JNICALL Java_premi_anprarm_Test_findplate(JNIEnv *env, jobject obj,jbyteArray source,jbyteArray dest,jint width,jint height) {LOGD("Java_premi_anprarm_Test_findplate");long start_time = currentTimeInMilliseconds();uint8_t* imageData;convertToFastCV(env,source,imageData,width,height);LOGD("Create processed buffer");//Allocate Processed imageint frameSize = width*height*3/2;uint8_t *thresholdImg = (uint8_t *)fcvMemAlloc(frameSize, 16);if( thresholdImg == NULL ){LOGD("Allocate filteredImgBuf failed");return 0;}else{memset(thresholdImg, 128, frameSize);}LOGD("Apply Threshold");//Apply ThresholdfcvFilterThresholdu8( (uint8_t*)imageData, width, height, thresholdImg, 128 );LOGD("Setting ByteArray Result");env->SetByteArrayRegion(dest,0,width*height*3/2,(jbyte*)thresholdImg);LOGD("Done");long end_time = currentTimeInMilliseconds();long time = end_time - start_time ;return (jlong)time;}