Canny edge detection C++ is showing error?












1















I'm a complete beginner in both native c++ and opencv so please excuse me if my question is foolish.Basically I'm passing the bitmap to the native C++ for canny edge detection by using opencv but the problem is it's showing error. My procedure of doing this might be wrong. So, can anyone please help me to fix this issue ?



Code Java:



Bitmap new_bitmap=bitmap.copy(Bitmap.Config.ARGB_8888,true);

int pixels = new int[bitmap.getWidth() * bitmap.getHeight()];

//Converting bitmap to byteArray
ByteArrayOutputStream stream = new ByteArrayOutputStream();
new_bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte FrameData = stream.toByteArray();
//bitmap.recycle();

ImageProcessing(bitmap.getWidth(), bitmap.getHeight(), FrameData, pixels);
new_bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
imgView.setImageBitmap(new_bitmap);


Code native C++:



#include <jni.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>

using namespace std;
using namespace cv;

Mat * mCanny = NULL;

extern "C"
jboolean
Java_opengl_community_testopencv_MainActivity_ImageProcessing(
JNIEnv* env, jobject thiz,
jint width, jint height,
jbyteArray NV21FrameData, jintArray outPixels)
{
jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0);
jint * poutPixels = env->GetIntArrayElements(outPixels, 0);

if ( mCanny == NULL )
{
mCanny = new Mat(height, width, CV_8UC1);
}

Mat mGray(height, width, CV_8UC1, (unsigned char *)pNV21FrameData);
Mat mResult(height, width, CV_8UC4, (unsigned char *)poutPixels);
IplImage srcImg = mGray;
IplImage CannyImg = *mCanny;
IplImage ResultImg = mResult;

cvCanny(&srcImg, &CannyImg, 80, 100, 3);
//cvSmooth(&srcImg,&CannyImg,3,0,0,0);
cvCvtColor(&CannyImg, &ResultImg, CV_GRAY2BGRA);
//cvCvtColor(&srcImg, &CannyImg, CV_BGR2GRAY);

env->ReleaseByteArrayElements(NV21FrameData, pNV21FrameData, 0);
env->ReleaseIntArrayElements(outPixels, poutPixels, 0);
return true;
}


Error:



11-19 23:12:30.264 2645-2645/opengl.community.testopencv E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
MAX_TEXTURE_SIZE: 16384









share|improve this question


















  • 1





    IplImage why arent you using Mat instead? Also IplImage CannyImg = *mCanny, you might want to use Mat CannyImg=mCanny.clone().

    – macroland
    Nov 20 '18 at 4:33













  • @macroland sir thanks for your answer but I've got this code from some website so could you please elaborate what to change in detail

    – anonymous
    Nov 20 '18 at 4:36











  • docs.opencv.org/3.4/d6/d5b/structIplImage.html

    – macroland
    Nov 20 '18 at 4:37











  • @macroland sir I tried your Mat technique but it didn't work

    – anonymous
    Nov 20 '18 at 6:23











  • Did you debug to see if height and width and other parameters are sound?

    – macroland
    Nov 20 '18 at 6:44
















1















I'm a complete beginner in both native c++ and opencv so please excuse me if my question is foolish.Basically I'm passing the bitmap to the native C++ for canny edge detection by using opencv but the problem is it's showing error. My procedure of doing this might be wrong. So, can anyone please help me to fix this issue ?



Code Java:



Bitmap new_bitmap=bitmap.copy(Bitmap.Config.ARGB_8888,true);

int pixels = new int[bitmap.getWidth() * bitmap.getHeight()];

//Converting bitmap to byteArray
ByteArrayOutputStream stream = new ByteArrayOutputStream();
new_bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte FrameData = stream.toByteArray();
//bitmap.recycle();

ImageProcessing(bitmap.getWidth(), bitmap.getHeight(), FrameData, pixels);
new_bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
imgView.setImageBitmap(new_bitmap);


Code native C++:



#include <jni.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>

using namespace std;
using namespace cv;

Mat * mCanny = NULL;

extern "C"
jboolean
Java_opengl_community_testopencv_MainActivity_ImageProcessing(
JNIEnv* env, jobject thiz,
jint width, jint height,
jbyteArray NV21FrameData, jintArray outPixels)
{
jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0);
jint * poutPixels = env->GetIntArrayElements(outPixels, 0);

if ( mCanny == NULL )
{
mCanny = new Mat(height, width, CV_8UC1);
}

Mat mGray(height, width, CV_8UC1, (unsigned char *)pNV21FrameData);
Mat mResult(height, width, CV_8UC4, (unsigned char *)poutPixels);
IplImage srcImg = mGray;
IplImage CannyImg = *mCanny;
IplImage ResultImg = mResult;

cvCanny(&srcImg, &CannyImg, 80, 100, 3);
//cvSmooth(&srcImg,&CannyImg,3,0,0,0);
cvCvtColor(&CannyImg, &ResultImg, CV_GRAY2BGRA);
//cvCvtColor(&srcImg, &CannyImg, CV_BGR2GRAY);

env->ReleaseByteArrayElements(NV21FrameData, pNV21FrameData, 0);
env->ReleaseIntArrayElements(outPixels, poutPixels, 0);
return true;
}


Error:



11-19 23:12:30.264 2645-2645/opengl.community.testopencv E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
MAX_TEXTURE_SIZE: 16384









share|improve this question


















  • 1





    IplImage why arent you using Mat instead? Also IplImage CannyImg = *mCanny, you might want to use Mat CannyImg=mCanny.clone().

    – macroland
    Nov 20 '18 at 4:33













  • @macroland sir thanks for your answer but I've got this code from some website so could you please elaborate what to change in detail

    – anonymous
    Nov 20 '18 at 4:36











  • docs.opencv.org/3.4/d6/d5b/structIplImage.html

    – macroland
    Nov 20 '18 at 4:37











  • @macroland sir I tried your Mat technique but it didn't work

    – anonymous
    Nov 20 '18 at 6:23











  • Did you debug to see if height and width and other parameters are sound?

    – macroland
    Nov 20 '18 at 6:44














1












1








1








I'm a complete beginner in both native c++ and opencv so please excuse me if my question is foolish.Basically I'm passing the bitmap to the native C++ for canny edge detection by using opencv but the problem is it's showing error. My procedure of doing this might be wrong. So, can anyone please help me to fix this issue ?



Code Java:



Bitmap new_bitmap=bitmap.copy(Bitmap.Config.ARGB_8888,true);

int pixels = new int[bitmap.getWidth() * bitmap.getHeight()];

//Converting bitmap to byteArray
ByteArrayOutputStream stream = new ByteArrayOutputStream();
new_bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte FrameData = stream.toByteArray();
//bitmap.recycle();

ImageProcessing(bitmap.getWidth(), bitmap.getHeight(), FrameData, pixels);
new_bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
imgView.setImageBitmap(new_bitmap);


Code native C++:



#include <jni.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>

using namespace std;
using namespace cv;

Mat * mCanny = NULL;

extern "C"
jboolean
Java_opengl_community_testopencv_MainActivity_ImageProcessing(
JNIEnv* env, jobject thiz,
jint width, jint height,
jbyteArray NV21FrameData, jintArray outPixels)
{
jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0);
jint * poutPixels = env->GetIntArrayElements(outPixels, 0);

if ( mCanny == NULL )
{
mCanny = new Mat(height, width, CV_8UC1);
}

Mat mGray(height, width, CV_8UC1, (unsigned char *)pNV21FrameData);
Mat mResult(height, width, CV_8UC4, (unsigned char *)poutPixels);
IplImage srcImg = mGray;
IplImage CannyImg = *mCanny;
IplImage ResultImg = mResult;

cvCanny(&srcImg, &CannyImg, 80, 100, 3);
//cvSmooth(&srcImg,&CannyImg,3,0,0,0);
cvCvtColor(&CannyImg, &ResultImg, CV_GRAY2BGRA);
//cvCvtColor(&srcImg, &CannyImg, CV_BGR2GRAY);

env->ReleaseByteArrayElements(NV21FrameData, pNV21FrameData, 0);
env->ReleaseIntArrayElements(outPixels, poutPixels, 0);
return true;
}


Error:



11-19 23:12:30.264 2645-2645/opengl.community.testopencv E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
MAX_TEXTURE_SIZE: 16384









share|improve this question














I'm a complete beginner in both native c++ and opencv so please excuse me if my question is foolish.Basically I'm passing the bitmap to the native C++ for canny edge detection by using opencv but the problem is it's showing error. My procedure of doing this might be wrong. So, can anyone please help me to fix this issue ?



Code Java:



Bitmap new_bitmap=bitmap.copy(Bitmap.Config.ARGB_8888,true);

int pixels = new int[bitmap.getWidth() * bitmap.getHeight()];

//Converting bitmap to byteArray
ByteArrayOutputStream stream = new ByteArrayOutputStream();
new_bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte FrameData = stream.toByteArray();
//bitmap.recycle();

ImageProcessing(bitmap.getWidth(), bitmap.getHeight(), FrameData, pixels);
new_bitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
imgView.setImageBitmap(new_bitmap);


Code native C++:



#include <jni.h>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>

using namespace std;
using namespace cv;

Mat * mCanny = NULL;

extern "C"
jboolean
Java_opengl_community_testopencv_MainActivity_ImageProcessing(
JNIEnv* env, jobject thiz,
jint width, jint height,
jbyteArray NV21FrameData, jintArray outPixels)
{
jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0);
jint * poutPixels = env->GetIntArrayElements(outPixels, 0);

if ( mCanny == NULL )
{
mCanny = new Mat(height, width, CV_8UC1);
}

Mat mGray(height, width, CV_8UC1, (unsigned char *)pNV21FrameData);
Mat mResult(height, width, CV_8UC4, (unsigned char *)poutPixels);
IplImage srcImg = mGray;
IplImage CannyImg = *mCanny;
IplImage ResultImg = mResult;

cvCanny(&srcImg, &CannyImg, 80, 100, 3);
//cvSmooth(&srcImg,&CannyImg,3,0,0,0);
cvCvtColor(&CannyImg, &ResultImg, CV_GRAY2BGRA);
//cvCvtColor(&srcImg, &CannyImg, CV_BGR2GRAY);

env->ReleaseByteArrayElements(NV21FrameData, pNV21FrameData, 0);
env->ReleaseIntArrayElements(outPixels, poutPixels, 0);
return true;
}


Error:



11-19 23:12:30.264 2645-2645/opengl.community.testopencv E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
MAX_TEXTURE_SIZE: 16384






android c++ opencv jni native






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 4:28









anonymousanonymous

5751617




5751617








  • 1





    IplImage why arent you using Mat instead? Also IplImage CannyImg = *mCanny, you might want to use Mat CannyImg=mCanny.clone().

    – macroland
    Nov 20 '18 at 4:33













  • @macroland sir thanks for your answer but I've got this code from some website so could you please elaborate what to change in detail

    – anonymous
    Nov 20 '18 at 4:36











  • docs.opencv.org/3.4/d6/d5b/structIplImage.html

    – macroland
    Nov 20 '18 at 4:37











  • @macroland sir I tried your Mat technique but it didn't work

    – anonymous
    Nov 20 '18 at 6:23











  • Did you debug to see if height and width and other parameters are sound?

    – macroland
    Nov 20 '18 at 6:44














  • 1





    IplImage why arent you using Mat instead? Also IplImage CannyImg = *mCanny, you might want to use Mat CannyImg=mCanny.clone().

    – macroland
    Nov 20 '18 at 4:33













  • @macroland sir thanks for your answer but I've got this code from some website so could you please elaborate what to change in detail

    – anonymous
    Nov 20 '18 at 4:36











  • docs.opencv.org/3.4/d6/d5b/structIplImage.html

    – macroland
    Nov 20 '18 at 4:37











  • @macroland sir I tried your Mat technique but it didn't work

    – anonymous
    Nov 20 '18 at 6:23











  • Did you debug to see if height and width and other parameters are sound?

    – macroland
    Nov 20 '18 at 6:44








1




1





IplImage why arent you using Mat instead? Also IplImage CannyImg = *mCanny, you might want to use Mat CannyImg=mCanny.clone().

– macroland
Nov 20 '18 at 4:33







IplImage why arent you using Mat instead? Also IplImage CannyImg = *mCanny, you might want to use Mat CannyImg=mCanny.clone().

– macroland
Nov 20 '18 at 4:33















@macroland sir thanks for your answer but I've got this code from some website so could you please elaborate what to change in detail

– anonymous
Nov 20 '18 at 4:36





@macroland sir thanks for your answer but I've got this code from some website so could you please elaborate what to change in detail

– anonymous
Nov 20 '18 at 4:36













docs.opencv.org/3.4/d6/d5b/structIplImage.html

– macroland
Nov 20 '18 at 4:37





docs.opencv.org/3.4/d6/d5b/structIplImage.html

– macroland
Nov 20 '18 at 4:37













@macroland sir I tried your Mat technique but it didn't work

– anonymous
Nov 20 '18 at 6:23





@macroland sir I tried your Mat technique but it didn't work

– anonymous
Nov 20 '18 at 6:23













Did you debug to see if height and width and other parameters are sound?

– macroland
Nov 20 '18 at 6:44





Did you debug to see if height and width and other parameters are sound?

– macroland
Nov 20 '18 at 6:44












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386242%2fcanny-edge-detection-c-is-showing-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386242%2fcanny-edge-detection-c-is-showing-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory