opencv_dart icon indicating copy to clipboard operation
opencv_dart copied to clipboard

How should i use the calcHist method

Open KartikGavhale opened this issue 1 year ago • 5 comments

How should i use the calcHist method? I tried the Described/suggested things to run this method but each step im getting error. Do you have some referance how can i do the color histogram.If possible need seperate histogram for each color i.e b r g.

KartikGavhale avatar Oct 02 '24 13:10 KartikGavhale

does this help https://github.com/rainyl/opencv_dart/blob/0fee178780af25a2c8fcb91226c8ca8b6f88db98/test/imgproc/imgproc_test.dart#L57 ?

abdelaziz-mahdy avatar Oct 02 '24 19:10 abdelaziz-mahdy

Yes , i was able to extract the pixel density thanks it was really helpfull @abdelaziz-mahdy . Can you please help me out on one more thing? Im trying to detect for example any object in shades of say red , im using method

cv.Mat hsv = cv.imdecode(bytes,cv.COLOR_BGR2HSV); cv.Mat mask1=cv.inRangebyScalar(mat, cv.Scalar(0, 100, 100), cv.Scalar(10, 255, 255)); // lower range cv.Mat mask2=cv.inRangebyScalar(mat, cv.Scalar(160, 100, 100), cv.Scalar(179, 255, 255)); // upper range

but im not sure in cv.Scalar are we putting rgb , bgr or hsv , because from the example videos of python the value which they used are not working , even when i tried the usinf rgb , brg or hsv im not getting the expected result. Can you please clarify this? Also if i have histogram data how can i deduce lower and upper limit of red or some method similar to cv.createTrackbar from python.

KartikGavhale avatar Oct 03 '24 05:10 KartikGavhale

Sorry I don't have the knowledge in the first question to answer you

But for createTrackbar it exists on highgui module and it should be implemented but it's not there so @rainyl do you know why it's not implemented in the dart side?

abdelaziz-mahdy avatar Oct 03 '24 06:10 abdelaziz-mahdy

Sorry for the late reply, I was on vacation recently.

@KartikGavhale As abdelaziz-mahdy suggested, you can always find an example in our tests at https://github.com/rainyl/opencv_dart/tree/main/test

And the code you attached above is incorrect

// Here, the flags of `imdecode` is same as `imread`, so you can't use the conversion flags like
// `cv.COLOR_BGR2HSV`, read more at https://docs.opencv.org/4.10.0/d4/da8/group__imgcodecs.html#gaad518fe65098fd32446bd5b9c4f8b531
cv.Mat hsv = cv.imdecode(bytes,cv.COLOR_BGR2HSV);
cv.Mat mask1=cv.inRangebyScalar(mat, cv.Scalar(0, 100, 100), cv.Scalar(10, 255, 255)); // lower range
cv.Mat mask2=cv.inRangebyScalar(mat, cv.Scalar(160, 100, 100), cv.Scalar(179, 255, 255)); // upper range

but im not sure in cv.Scalar are we putting rgb , bgr or hsv

AFAIK, the order of cv.Scalar is same as the Mat you are processing, i.e., if Mat is BGR, cv.Scalar should be constructed by BGR like final lb = cv.Scalar(B, G, R, X), (here X is not used, so it can be any values), more info here: https://docs.opencv.org/4.10.0/d2/de8/group__core__array.html#ga48af0ab51e36436c5d04340e036ce981

some method similar to cv.createTrackbar from python. But for createTrackbar it exists on highgui module and it should be implemented but it's not there so @rainyl do you know why it's not implemented in the dart side?

This project was started from gocv, so same as gocv, Window and Trackbar are implemented via Classes, find more details here: https://pub.dev/documentation/opencv_dart/latest/cv.highgui/Trackbar-class.html and https://github.com/rainyl/opencv_dart/blob/main/test/highgui_test.dart

Maybe we can implement these methods in the future: https://docs.opencv.org/4.10.0/d7/dfc/group__highgui.html#gaf78d2155d30b728fc413803745b67a9b

rainyl avatar Oct 05 '24 10:10 rainyl

@rainyl Thanks you for the clarification and suggetions.

KartikGavhale avatar Oct 06 '24 07:10 KartikGavhale

If you have no more questions, I am going to close this issue, feel free to reopen it if needed.

rainyl avatar Oct 17 '24 07:10 rainyl