Skip to content

How should i use the calcHist method #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KartikGavhale opened this issue Oct 2, 2024 · 6 comments
Closed

How should i use the calcHist method #257

KartikGavhale opened this issue Oct 2, 2024 · 6 comments
Labels
question Further information is requested

Comments

@KartikGavhale
Copy link

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 KartikGavhale added the question Further information is requested label Oct 2, 2024
@abdelaziz-mahdy
Copy link
Contributor

does this help

test('cv.calcBackProject', () {
?

@KartikGavhale
Copy link
Author

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.

@abdelaziz-mahdy
Copy link
Contributor

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?

@rainyl
Copy link
Owner

rainyl commented Oct 5, 2024

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

@KartikGavhale
Copy link
Author

@rainyl Thanks you for the clarification and suggetions.

@rainyl
Copy link
Owner

rainyl commented Oct 17, 2024

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

@rainyl rainyl closed this as completed Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants