How to detect edges using Canny in Android in low brightness and ignore shadows?How to save an Android Activity state using save instance state?How to check if a service is running on Android?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?How do I display an alert dialog on Android?Detect whether there is an Internet connection available on AndroidHow do I rotate the Android emulator display?How to get the build/version number of your Android application?How to manage startActivityForResult on Android?How to detect a Christmas Tree?

Why cruise at 7000' in an A319?

How much will studying magic in an academy cost?

Is there a maximum distance from a planet that a moon can orbit?

If you snatch, I trade

How to make clear to people I don't want to answer their "Where are you from?" question?

Unusual mail headers, evidence of an attempted attack. Have I been pwned?

Sci fi short story, robot city that nags people about health

What is the mechanical difference between the Spectator's Create Food and Water action and the Banshee's Undead Nature Trait?

Can any NP-Complete Problem be solved using at most polynomial space (but while using exponential time?)

Why is the voltage measurement of this circuit different when the switch is on?

Is it possible writing coservation of relativistic energy in this naive way?

Why do textbooks often include the solutions to odd or even numbered problems but not both?

A STL-like vector implementation in C++

Impossible darts scores

Long term BTC investing

Why do some games show lights shine thorugh walls?

The Target Principal Name Is Incorrect. Cannot Generate SSPI Context (SQL or AD Issue)?

Why did pressing the joystick button spit out keypresses?

Can we put equal sign after aggregate functions in sql?

Why do all the teams that I have worked with always finish a sprint without completion of all the stories?

Inverse-quotes-quine

3D Crossword, Cryptic, Statue View & Maze

How convert text to hex value?

Accidentals and ties



How to detect edges using Canny in Android in low brightness and ignore shadows?


How to save an Android Activity state using save instance state?How to check if a service is running on Android?Why is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?How do I display an alert dialog on Android?Detect whether there is an Internet connection available on AndroidHow do I rotate the Android emulator display?How to get the build/version number of your Android application?How to manage startActivityForResult on Android?How to detect a Christmas Tree?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm developing an Android application to perform image segmentation using Opencv in real time.



The problem is when I applied Canny edge detector, there is always gaps in detected contours even in high brightness environment but detection is accurate when I turn on my smartphone flash.



And when I turn on flash, shadows are also detected which isn't good for my purposes.



I tried to enhance pixels values using Opencv method convertTo and I tried also increasing camera exposure, but in vain.



Here is my code



 Imgproc.cvtColor(orr, orr, Imgproc.COLOR_RGB2HSV);

Core.split(orr, channels);

orr = channels.get(1);

//orr.convertTo(orr, orr.type(), 1.1);

Core.meanStdDev(orr, mu, stddev);

CLAHE clahe = Imgproc.createCLAHE();

clahe.setClipLimit(1);

clahe.apply(orr, orr);

clahe.collectGarbage();

Imgproc.GaussianBlur(orr, orr, new Size(5, 5), 3);

Imgproc.Canny(orr, orr, mu.get(0, 0)[0], stddev.get(0, 0)[0], 3, false);


Imgproc.morphologyEx(orr, orr, Imgproc.MORPH_CLOSE, kernell);

Imgproc.dilate(orr, orr, Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3)));

Imgproc.findContours(orr, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

for (int i = contours.size() - 1; i >= 0; i--)


if (contours.size() > 0)
MatOfPoint2f approxCurve = new MatOfPoint2f();
rectList.clear();
for (int idx = 0; idx < contours.size(); idx++)
//Convert contours(i) from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(idx).toArray());
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true) * 0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint(approxCurve.toArray());

// Get bounding rect of contour
Rect rectt = Imgproc.boundingRect(points);
rectList.add(rect);
Mat miniature = new Mat(orr, new Rect(rectt.tl(), rectt.br()));
mats.add(miniature);

// draw enclosing rectangle (all same color, but you could use variable i to make them unique)
Imgproc.rectangle(rotated, rectt.tl(), rectt.br(), new Scalar(255, 0, 0));



Imgproc.resize(rotated, rotated, new Size(rotated.width() * 2, rotated.height() * 2));

long e2 = Core.getTickCount();
long e = e2 - e1;
double time = e / Core.getTickFrequency();


Here is the image without flash



enter image description here



And here is the output result with flash



enter image description here



So my question is what can I do to have accurate detection without using phone flash ?










share|improve this question






















  • Have you tried reducing threshold1 and threshold2?

    – greeble31
    Mar 25 at 22:04











  • Threshold is auto calculated using mean .

    – Amine
    Mar 25 at 23:12











  • I hear you, but the threshold calculated is not suitable for your purposes. I think you've just demonstrated that. Threshold should be regarded as a tunable parameter, here. After all, you're not using AI; you're using Canny.

    – greeble31
    Mar 25 at 23:23











  • Thank you Sir, but i need it to be generic for most cases, so when I use low threshold, detection is bright places won't work

    – Amine
    Mar 26 at 1:14


















1















I'm developing an Android application to perform image segmentation using Opencv in real time.



The problem is when I applied Canny edge detector, there is always gaps in detected contours even in high brightness environment but detection is accurate when I turn on my smartphone flash.



And when I turn on flash, shadows are also detected which isn't good for my purposes.



I tried to enhance pixels values using Opencv method convertTo and I tried also increasing camera exposure, but in vain.



Here is my code



 Imgproc.cvtColor(orr, orr, Imgproc.COLOR_RGB2HSV);

Core.split(orr, channels);

orr = channels.get(1);

//orr.convertTo(orr, orr.type(), 1.1);

Core.meanStdDev(orr, mu, stddev);

CLAHE clahe = Imgproc.createCLAHE();

clahe.setClipLimit(1);

clahe.apply(orr, orr);

clahe.collectGarbage();

Imgproc.GaussianBlur(orr, orr, new Size(5, 5), 3);

Imgproc.Canny(orr, orr, mu.get(0, 0)[0], stddev.get(0, 0)[0], 3, false);


Imgproc.morphologyEx(orr, orr, Imgproc.MORPH_CLOSE, kernell);

Imgproc.dilate(orr, orr, Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3)));

Imgproc.findContours(orr, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

for (int i = contours.size() - 1; i >= 0; i--)


if (contours.size() > 0)
MatOfPoint2f approxCurve = new MatOfPoint2f();
rectList.clear();
for (int idx = 0; idx < contours.size(); idx++)
//Convert contours(i) from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(idx).toArray());
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true) * 0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint(approxCurve.toArray());

// Get bounding rect of contour
Rect rectt = Imgproc.boundingRect(points);
rectList.add(rect);
Mat miniature = new Mat(orr, new Rect(rectt.tl(), rectt.br()));
mats.add(miniature);

// draw enclosing rectangle (all same color, but you could use variable i to make them unique)
Imgproc.rectangle(rotated, rectt.tl(), rectt.br(), new Scalar(255, 0, 0));



Imgproc.resize(rotated, rotated, new Size(rotated.width() * 2, rotated.height() * 2));

long e2 = Core.getTickCount();
long e = e2 - e1;
double time = e / Core.getTickFrequency();


Here is the image without flash



enter image description here



And here is the output result with flash



enter image description here



So my question is what can I do to have accurate detection without using phone flash ?










share|improve this question






















  • Have you tried reducing threshold1 and threshold2?

    – greeble31
    Mar 25 at 22:04











  • Threshold is auto calculated using mean .

    – Amine
    Mar 25 at 23:12











  • I hear you, but the threshold calculated is not suitable for your purposes. I think you've just demonstrated that. Threshold should be regarded as a tunable parameter, here. After all, you're not using AI; you're using Canny.

    – greeble31
    Mar 25 at 23:23











  • Thank you Sir, but i need it to be generic for most cases, so when I use low threshold, detection is bright places won't work

    – Amine
    Mar 26 at 1:14














1












1








1








I'm developing an Android application to perform image segmentation using Opencv in real time.



The problem is when I applied Canny edge detector, there is always gaps in detected contours even in high brightness environment but detection is accurate when I turn on my smartphone flash.



And when I turn on flash, shadows are also detected which isn't good for my purposes.



I tried to enhance pixels values using Opencv method convertTo and I tried also increasing camera exposure, but in vain.



Here is my code



 Imgproc.cvtColor(orr, orr, Imgproc.COLOR_RGB2HSV);

Core.split(orr, channels);

orr = channels.get(1);

//orr.convertTo(orr, orr.type(), 1.1);

Core.meanStdDev(orr, mu, stddev);

CLAHE clahe = Imgproc.createCLAHE();

clahe.setClipLimit(1);

clahe.apply(orr, orr);

clahe.collectGarbage();

Imgproc.GaussianBlur(orr, orr, new Size(5, 5), 3);

Imgproc.Canny(orr, orr, mu.get(0, 0)[0], stddev.get(0, 0)[0], 3, false);


Imgproc.morphologyEx(orr, orr, Imgproc.MORPH_CLOSE, kernell);

Imgproc.dilate(orr, orr, Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3)));

Imgproc.findContours(orr, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

for (int i = contours.size() - 1; i >= 0; i--)


if (contours.size() > 0)
MatOfPoint2f approxCurve = new MatOfPoint2f();
rectList.clear();
for (int idx = 0; idx < contours.size(); idx++)
//Convert contours(i) from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(idx).toArray());
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true) * 0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint(approxCurve.toArray());

// Get bounding rect of contour
Rect rectt = Imgproc.boundingRect(points);
rectList.add(rect);
Mat miniature = new Mat(orr, new Rect(rectt.tl(), rectt.br()));
mats.add(miniature);

// draw enclosing rectangle (all same color, but you could use variable i to make them unique)
Imgproc.rectangle(rotated, rectt.tl(), rectt.br(), new Scalar(255, 0, 0));



Imgproc.resize(rotated, rotated, new Size(rotated.width() * 2, rotated.height() * 2));

long e2 = Core.getTickCount();
long e = e2 - e1;
double time = e / Core.getTickFrequency();


Here is the image without flash



enter image description here



And here is the output result with flash



enter image description here



So my question is what can I do to have accurate detection without using phone flash ?










share|improve this question














I'm developing an Android application to perform image segmentation using Opencv in real time.



The problem is when I applied Canny edge detector, there is always gaps in detected contours even in high brightness environment but detection is accurate when I turn on my smartphone flash.



And when I turn on flash, shadows are also detected which isn't good for my purposes.



I tried to enhance pixels values using Opencv method convertTo and I tried also increasing camera exposure, but in vain.



Here is my code



 Imgproc.cvtColor(orr, orr, Imgproc.COLOR_RGB2HSV);

Core.split(orr, channels);

orr = channels.get(1);

//orr.convertTo(orr, orr.type(), 1.1);

Core.meanStdDev(orr, mu, stddev);

CLAHE clahe = Imgproc.createCLAHE();

clahe.setClipLimit(1);

clahe.apply(orr, orr);

clahe.collectGarbage();

Imgproc.GaussianBlur(orr, orr, new Size(5, 5), 3);

Imgproc.Canny(orr, orr, mu.get(0, 0)[0], stddev.get(0, 0)[0], 3, false);


Imgproc.morphologyEx(orr, orr, Imgproc.MORPH_CLOSE, kernell);

Imgproc.dilate(orr, orr, Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3)));

Imgproc.findContours(orr, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

for (int i = contours.size() - 1; i >= 0; i--)


if (contours.size() > 0)
MatOfPoint2f approxCurve = new MatOfPoint2f();
rectList.clear();
for (int idx = 0; idx < contours.size(); idx++)
//Convert contours(i) from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(idx).toArray());
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true) * 0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);

//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint(approxCurve.toArray());

// Get bounding rect of contour
Rect rectt = Imgproc.boundingRect(points);
rectList.add(rect);
Mat miniature = new Mat(orr, new Rect(rectt.tl(), rectt.br()));
mats.add(miniature);

// draw enclosing rectangle (all same color, but you could use variable i to make them unique)
Imgproc.rectangle(rotated, rectt.tl(), rectt.br(), new Scalar(255, 0, 0));



Imgproc.resize(rotated, rotated, new Size(rotated.width() * 2, rotated.height() * 2));

long e2 = Core.getTickCount();
long e = e2 - e1;
double time = e / Core.getTickFrequency();


Here is the image without flash



enter image description here



And here is the output result with flash



enter image description here



So my question is what can I do to have accurate detection without using phone flash ?







android image-processing computer-vision opencv4android canny-operator






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 9:42









AmineAmine

1,0701 gold badge4 silver badges15 bronze badges




1,0701 gold badge4 silver badges15 bronze badges












  • Have you tried reducing threshold1 and threshold2?

    – greeble31
    Mar 25 at 22:04











  • Threshold is auto calculated using mean .

    – Amine
    Mar 25 at 23:12











  • I hear you, but the threshold calculated is not suitable for your purposes. I think you've just demonstrated that. Threshold should be regarded as a tunable parameter, here. After all, you're not using AI; you're using Canny.

    – greeble31
    Mar 25 at 23:23











  • Thank you Sir, but i need it to be generic for most cases, so when I use low threshold, detection is bright places won't work

    – Amine
    Mar 26 at 1:14


















  • Have you tried reducing threshold1 and threshold2?

    – greeble31
    Mar 25 at 22:04











  • Threshold is auto calculated using mean .

    – Amine
    Mar 25 at 23:12











  • I hear you, but the threshold calculated is not suitable for your purposes. I think you've just demonstrated that. Threshold should be regarded as a tunable parameter, here. After all, you're not using AI; you're using Canny.

    – greeble31
    Mar 25 at 23:23











  • Thank you Sir, but i need it to be generic for most cases, so when I use low threshold, detection is bright places won't work

    – Amine
    Mar 26 at 1:14

















Have you tried reducing threshold1 and threshold2?

– greeble31
Mar 25 at 22:04





Have you tried reducing threshold1 and threshold2?

– greeble31
Mar 25 at 22:04













Threshold is auto calculated using mean .

– Amine
Mar 25 at 23:12





Threshold is auto calculated using mean .

– Amine
Mar 25 at 23:12













I hear you, but the threshold calculated is not suitable for your purposes. I think you've just demonstrated that. Threshold should be regarded as a tunable parameter, here. After all, you're not using AI; you're using Canny.

– greeble31
Mar 25 at 23:23





I hear you, but the threshold calculated is not suitable for your purposes. I think you've just demonstrated that. Threshold should be regarded as a tunable parameter, here. After all, you're not using AI; you're using Canny.

– greeble31
Mar 25 at 23:23













Thank you Sir, but i need it to be generic for most cases, so when I use low threshold, detection is bright places won't work

– Amine
Mar 26 at 1:14






Thank you Sir, but i need it to be generic for most cases, so when I use low threshold, detection is bright places won't work

– Amine
Mar 26 at 1:14













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%2f55334947%2fhow-to-detect-edges-using-canny-in-android-in-low-brightness-and-ignore-shadows%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%2f55334947%2fhow-to-detect-edges-using-canny-in-android-in-low-brightness-and-ignore-shadows%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현