Note that the order of colors is BGR-A not RGB-A.
Read it more from http://stackoverflow.com/questions/367449/bgr-color-space
//static imports
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
//non-static imports
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class ColorDetect {
//color range of red like color
static CvScalar min = cvScalar(0, 0, 130, 0);//BGR-A
static CvScalar max= cvScalar(140, 110, 255, 0);//BGR-A
public static void main(String[] args) {
//read image
IplImage orgImg = cvLoadImage("colordetectimage.jpg");
//create binary image of original size
IplImage imgThreshold = cvCreateImage(cvGetSize(orgImg), 8, 1);
//apply thresholding
cvInRangeS(orgImg, min, max, imgThreshold);
//smooth filter- median
cvSmooth(imgThreshold, imgThreshold, CV_MEDIAN, 13);
//save
cvSaveImage("threshold.jpg", imgThreshold);
}
}
//Red color
detected output image
Red like color detected |
#you can alter the range of red color (min, max) .
hi... can u develop corrsponding code 4 android???
ReplyDeleten where are we suppose to save the input image
Hello Asha, in my example the image will be saved at project's folder.
DeleteSee my answer to Aman's question for your other question.
hi...I am having same problem as Asha can you tell me how to use this in android platform...pls its urgent
ReplyDeletehello Aman and Asha , I haven't used JavaCV in android. But AFAIK, you should use native calls OpenCV functions from Android code. Do more research.
DeleteThe following resources will certainly help you.
http://www.stanford.edu/~zxwang/android_opencv.html
http://opencv.itseez.com/doc/tutorials/introduction/android_binary_package/android_binary_package_using_with_NDK.html
hello mister, i want to ask, what is code "static CvScalar min = cvScalar(0, 0, 130, 0); static CvScalar max= cvScalar(140, 110, 255, 0);" mean ? what is HSV value ,,
ReplyDeletedo you have formula or anything,to calc number cvScalar if i want to change color to detection.... e.g (yellow or green)
thanks
As my comment suggest they represent : color range of red like color.
DeleteFor HSV Scale, refer to :
http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/javacv-image-thresholding-hsv-color.html
I haven't used any formula. Its just game of hit/trial to achieve close range.
ok thanks for ur suggest.... I almost can detect colors (yellow ang green),
DeleteI can conclude that cvScalar parameter's is cvScalar(G, B, R, A);
You are right about (G, B, R, A)
Deletewhat do you have coding steganografi with java?
ReplyDeleteemail to: bayuwinarta@yahoo.com
HI
ReplyDeleteDO you know how to track same color objects in different place with independent way. that meant i need to track object 1, object 2, object 3... likewise i want to get 4 red colored object with each coordinates need each one as independent way
OpenCV Error: Bad argument (Array should be CvMat or IplImage) in unknown function, file ..\..\..\src\opencv\modules\core\src\array.cpp, line 1238
ReplyDeleteException in thread "main" java.lang.RuntimeException: ..\..\..\src\opencv\modules\core\src\array.cpp:1238: error: (-5) Array should be CvMat or IplImage
at com.googlecode.javacv.cpp.opencv_core.cvGetSize(Native Method)