Ask Your Question
0

Gaussian blur and adaptive threshold issue on greyscale mat

asked 2013-02-04 11:52:26 -0600

himanshu jain gravatar image

updated 2013-02-04 13:39:02 -0600

I am trying to convert inputframe received in onCameraFrame into greyscale so that i can apply gaussianblur and adaptivethreshold. But moment i create gaussian mat and apply blur it sort of hang does not display any kind of real frame.

mGrayMat = new Mat(height, width, CvType.CV_8UC1);
// Where as inputFrame received from onCameraFrame 
inputFrame.copyTo(mGrayMat);
mGaussianMat.create(mGrayMat.size(), mGrayMat.type());
Imgproc.GaussianBlur(mGrayMat, mGaussianMat, new Size(7,7), 0.0);

Not sure is this a right way of doing it ??

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-02-04 13:46:21 -0600

  1. onCameraFrame callback must return Mat object, that will be show on the screen. 8UC4 RGBA Mat is expected. It looks like your code return some invalid or unexpected Mat.
  2. You can set preview frame format to gray scale by setPreviewFormat method of your View object. So, color conversion to gray scale will not be needed.
edit flag offensive delete link more

Comments

Hey Alexander , Thanks for your reply , Now what i am doing are as follow 1) I get GreyScale as InputFrame
2) I created Gaussian Mat mGaussianMat.create(inputFrame.size(), inputFrame.type());
Imgproc.GaussianBlur(inputFrame, mGaussianMat, new Size(7,7), 1.5,1.5); 3) Then i apply adaptive threshold mThresHoldMat.create(mGaussianMat.size(), mGaussianMat.type()); Imgproc.adaptiveThreshold(mGaussianMat, mThresHoldMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY,11, 2);
4) Then invert image
Core.bitwise_not(mThresHoldMat, mThresHoldMat); 5) then apply morphology filter Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3,3), new Point(1,1)); Imgproc.dilate(mThresHoldMat, mThresHoldMat, kernel); 6) Finally,display it on screen now working!

himanshu jain gravatar imagehimanshu jain ( 2013-02-04 14:15:57 -0600 )edit

Please confirm if all above steps are correct way of getting binary image because my ultimate goal is to detect blob from frame. Is there any functionality in OpenCV that has Infra red module capability or do i need to make camera externally as IR camera ?.

himanshu jain gravatar imagehimanshu jain ( 2013-02-04 14:19:43 -0600 )edit
  1. At the last step you need to convert you binary image to rgba using Imgproc.cvtColor with type of conversion Imgproc.COLOR_GRAY2BGRA and return result image from oCameraFrame call back.

  2. You can ensure that your algorithm works fine. You can display result of every steps using the same color conversion.

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2013-02-05 00:47:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-02-04 11:52:26 -0600

Seen: 1,307 times

Last updated: Feb 04 '13