Ask Your Question

HasanGhaforian's profile - activity

2019-10-23 12:47:23 -0600 received badge  Notable Question (source)
2019-06-14 05:25:23 -0600 received badge  Popular Question (source)
2018-04-15 06:16:03 -0600 received badge  Taxonomist
2018-01-25 04:14:57 -0600 received badge  Popular Question (source)
2017-09-28 08:22:27 -0600 received badge  Notable Question (source)
2017-03-31 01:19:19 -0600 received badge  Famous Question (source)
2016-12-07 06:27:21 -0600 received badge  Famous Question (source)
2016-08-11 02:40:59 -0600 received badge  Nice Question (source)
2016-06-17 06:00:18 -0600 received badge  Popular Question (source)
2016-06-08 07:14:28 -0600 received badge  Notable Question (source)
2016-03-29 19:15:58 -0600 received badge  Notable Question (source)
2015-12-23 06:59:25 -0600 received badge  Popular Question (source)
2015-11-30 11:10:01 -0600 received badge  Popular Question (source)
2015-01-21 12:47:10 -0600 commented question Why warping images by Homography matrix,cut image?

@StevenPuttemans Do you mean that my result is natural?But I want to create an App that stitches images,without cut any part of images.I expect to achieve the latest image.Excuse me,if I did not understand what you mean.

2015-01-20 09:30:31 -0600 asked a question Why warping images by Homography matrix,cut image?

I followed Panorama – Image Stitching in OpenCV to do same task on Android,by using openCV4Android.My problem is in about warping image by founded homography matrix.I tested these images(those are from above linked reference):

image1:

enter image description here

image2:

enter image description here

Result of warping image1 by founded homography is:

enter image description here

You can see that result is good warped but first part of that(left side) is cut! So stitching result was:

enter image description here

And result of above referenced link page,is:

enter image description here

Why warping by homography cut that?Or may be I did some things wrong?

2015-01-02 21:27:46 -0600 asked a question How to draw good matches between two images by features2d?

I am doing a project on panoramic stitching of Images using openCV4Ansroid and I want to use features2d to draw good matches (not all matches) between two images.So I used this snippet of code:

Mat gray1 = //image1 converted to gray
Mat gray2 = //image2 converted to gray

MatOfDMatch matches = new MatOfDMatch();
MatOfDMatch gm = new MatOfDMatch();

LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
MatOfKeyPoint keypoints_object = new MatOfKeyPoint();
MatOfKeyPoint keypoints_scene = new MatOfKeyPoint();
Mat descriptors_object = new Mat();
Mat descriptors_scene = new Mat();
FeatureDetector fd = FeatureDetector.create(FeatureDetector.ORB);

fd.detect(gray1, keypoints_object);
fd.detect(gray2, keypoints_scene);
// – Step 2: Calculate descriptors (feature vectors)
DescriptorExtractor extractor = DescriptorExtractor
.create(DescriptorExtractor.ORB);

extractor.compute(gray1, keypoints_object, descriptors_object);
extractor.compute(gray2, keypoints_scene, descriptors_scene);
DescriptorMatcher matcher = DescriptorMatcher
.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

matcher.match(descriptors_object, descriptors_scene, matches);

double max_dist = 0;
double min_dist = 100;
List<DMatch> matchesList = matches.toList();

// – Quick calculation of max and min distances between keypoints
for (int i = 0; i < descriptors_object.rows(); i++) {
    Double dist = (double) matchesList.get(i).distance;
    if (dist < min_dist)
    min_dist = dist;
    if (dist > max_dist)
    max_dist = dist;
}

for (int i = 0; i < descriptors_object.rows(); i++) {
    if (matchesList.get(i).distance <= 3 * min_dist) {
        good_matches.addLast(matchesList.get(i));
    }
}

gm.fromList(good_matches);

List<KeyPoint> keypoints_objectList = keypoints_object.toList();
List<KeyPoint> keypoints_sceneList = keypoints_scene.toList();

MatOfKeyPoint matOfObjectGoodKeyPoints = new MatOfKeyPoint();
MatOfKeyPoint matOfSceneGoodKeyPoints = new MatOfKeyPoint();
LinkedList<KeyPoint> listOfObjectGoodKeyPoints = new LinkedList<KeyPoint>();
LinkedList<KeyPoint> listOfSceneGoodKeyPoints = new LinkedList<KeyPoint>();
for (int i = 0; i < good_matches.size(); i++) {
    listOfObjectGoodKeyPoints.addLast(keypoints_objectList
    .get(good_matches.get(i).queryIdx));
    listOfSceneGoodKeyPoints.addLast(keypoints_sceneList
    .get(good_matches.get(i).trainIdx));
}
matOfObjectGoodKeyPoints.fromList(listOfObjectGoodKeyPoints);
matOfSceneGoodKeyPoints.fromList(listOfSceneGoodKeyPoints);

// feature and connection colors
Scalar RED = new Scalar(255, 0, 0);
// output image
Mat outputImg = new Mat();
MatOfByte drawnMatches = new MatOfByte();
// this would draw good matches,but error occurs here:
Features2d.drawMatches(gray1, matOfObjectGoodKeyPoints, gray2,
matOfSceneGoodKeyPoints, gm, outputImg, Scalar.all(-1), RED,
drawnMatches, Features2d.NOT_DRAW_SINGLE_POINTS);

But in run time,this error occurs:

CvException ... features2d/src/draw.cpp:208: error: (-215) i2 >= 0 && i2 < static_cast(keypoints2.size())

What is the problem in code?

2015-01-02 21:13:14 -0600 received badge  Enthusiast
2014-12-29 22:32:54 -0600 asked a question features2d error

I want to use features2d to draw good matches (not all matches) between two images.But in run time,this error occurs:

CvException ... features2d/src/draw.cpp:208: error: (-215) i2 >= 0 && i2 < static_cast<int>(keypoints2.size())

I do not know what is the problem of above code?

2014-12-26 03:30:48 -0600 asked a question Imgproc.COLOR_YUV420i2RGB in openCV4Android2.4.8.2

I want to use some codes of android-opencv-panorama.There is this line of code:

Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420i2RGB, 4);

But COLOR_YUV420i2RGB is not a valid field in Imgproc class.What field of that class can be replaced,without arising problem?

2014-12-09 13:53:37 -0600 marked best answer Android using drawContours to fill region

It must be simple to find contours and fill them with specific color.I want to find contours in this simple image:

image description

So I used this snippet of code(here iv is an instance of ImageView and bmp is a Bitmap created from above image):

Mat src = new Mat();
Utils.bitmapToMat(bmp, src);
Imgproc.cvtColor(src, src, Imgproc.COLOR_RGBA2GRAY);

Imgproc.Canny(src, src, 50, 200);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
// find contours:
Imgproc.findContours(src, contours, hierarchy, Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
    Imgproc.drawContours(src, contours, contourIdx, new Scalar(0, 0, 255), -1);
}
// create a blank temp bitmap:
Bitmap tempBmp1 = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(),
bmp.getConfig());

Utils.matToBitmap(src, tempBmp1);
iv.setImageBitmap(tempBmp1);

But the result is a totally black image like this:

image description

Did I do any thing wrong?

2014-12-09 13:12:58 -0600 marked best answer android change brightness and contrast of image

Hello.I'm new by opencv and I do not know programming with c or c++,so excuse me if my question is weak and it's answer is obvious.Of course,before I ask this question,did a lot searching in Google,opencv Q\A and stackoverflow,but unfortunately I do not found answer.

I have to change brightness and contrast of a bitmap.I know how to get a Mat form bitmap in android.But I could not find any method in Imageproc class to change contrast and brightness of bitmap.Is there any way in java (without using native codes) to do those processes?

2014-11-21 23:01:20 -0600 asked a question Detect text lines by Hough Transform

In Android App,I have to detect text lines in images.I want to use Hough Transform to detect lines.You can see an image below:

image description

I got edges in image by canny filter,then I applied Hough Transform on canny image:

Size size = canny.size();
Mat lines = new Mat();
int lineGap = 20;
double sum1 = 0;
Imgproc.HoughLinesP(canny, lines, 1, Math.PI / 180, 100, size.width / 2.f, lineGap);

Result for above image, looks like this:

image description

You can see tree text lines are detected.So I added line's thickness by applying dilate on canny image:

Mat dilate = new Mat();
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));
Imgproc.dilate(canny, dilate, kernel);
int lineGap = 20;
double sum1 = 0;
Imgproc.HoughLinesP(dilate, lines, 1, Math.PI / 180, 100, size.width / 2.f, lineGap);

I drew detected lines on empty black background.Result is shown below:

image description

You can see number of detected text lines is decreased,although I had added thickness of lines and did not change amount of minLineLength or maxLineGap,also when I apply dilation no white pixel remove from image!

Again I added thickness of lines by doing dilation with kernel of size(30,30):

Mat dilate = new Mat();
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30));
Imgproc.dilate(canny, dilate, kernel);
int lineGap = 20;
double sum1 = 0;
Imgproc.HoughLinesP(dilate, lines, 1, Math.PI / 180, 100, size.width / 2.f, lineGap);

Result is:

image description

Now my question is:
Why in each level when I add number of white pixels and do not change minLineLength or maxLineGap,Hough Transform do not detect some lines that were detected in previous level?

2014-11-11 22:57:53 -0600 asked a question Android Smooth perspective correction?

Hello.I can correct perspective of rotated card that is in image by the way that is described in Automatic perspective correction for quadrilateral objects.It is fine and works well.But the result of correction appears suddenly.I want to do that smoothly.I mean I want to move card smoothly (not suddenly) to front us,until card be full screen.Excuse me for poor description,but you can see similar process in CamScanner after click on confirm button on interesting area selecting Activity.

Thank you for your attention.

2014-10-19 13:58:43 -0600 received badge  Critic (source)
2014-10-15 04:41:22 -0600 asked a question openCV4Android how to find specific value in mat?

I want to get elements of a matrix where their values are specific,for example at the end of Image Segmentation with Watershed Algorithm I have to use similar of this code in java:

img[markers == -1] = [255,0,0]

I can do that by using nested loop in java by getting each pixel's value and ...,as described here ,but is there better way(with respect to performance and being clean code) to do same task?

2014-10-14 21:38:21 -0600 commented answer Convert CV_8UC4 to CV_8UC3,in openCV4Android?

@rwong +1 vote for your good explanation and good comment.Thank you!

2014-10-14 13:07:22 -0600 asked a question Convert CV_8UC4 to CV_8UC3,in openCV4Android?

Here src is an instance of Mat and it's type is CV_8UC4.I want to use src as first parameter of watershed:

public static void watershed(Mat image, Mat markers)

In about first parameter of watershed,Docs say:

Parameters:
image - Input 8-bit 3-channel image.

So I have to convert src from CV_8UC4 to CV_8UC3.I used this to convert src type:

src.convertTo(src, CvType.CV_8UC3);

But after that,when I debug code,type of src is CV_8UC4 yet and no CV_8UC3.Did I do any thing wrong?And how I can convert it's type?

2014-10-14 07:38:17 -0600 commented question Error on using copyTo in openCV4Android

@berak But I want to copy some pixels,not all of them.

2014-10-14 05:42:07 -0600 marked best answer connectedComponents in openCV4Android?

Most of functions in openCV have similar name in openCV4Android.But I can not find relative method for cv2.connectedComponents() in openCV4Android.Do you know how I can find it?

Edit:

I saw that function in this page: Image Segmentation with Watershed Algorithm.

2014-10-14 04:24:53 -0600 commented question Error on using copyTo in openCV4Android

@berak Is not that exactly what I used in my code?

2014-10-14 03:47:25 -0600 commented question Error on using copyTo in openCV4Android

@berak Yes,error say that it must be 8bit,but why?What is it's logic?Docs does not say any thing about depth of mask.

2014-10-14 03:29:02 -0600 commented question Error on using copyTo in openCV4Android

@berak unknown is an initialized instance of Mat class.If it was not initialized,then null pointer exception had been occurred.It's size and type is same as marker and sure_bg.

2014-10-14 03:13:06 -0600 asked a question Error on using copyTo in openCV4Android

It is a simple code:

sure_bg.copyTo(marker, unknown);

Here sure_bg , marker and unknown are Mats of the same size and same type(size:(333,250)-type:CV_32FC1).But in run time this error occurs:

E/cv::error()(393): OpenCV Error: Assertion failed (mask.depth() == CV_8U && (mcn == 1 || mcn == cn)) in void cv::Mat::copyTo(cv::OutputArray, cv::InputArray) ...

E/org.opencv.core.Mat(393): Mat::n_1copyTo__JJJ() caught cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/copy.cpp:274: error: (-215) mask.depth() == CV_8U && (mcn == 1 || mcn == cn) in function void cv::Mat::copyTo(cv::OutputArray, cv::InputArray) const

Why this error occurs,while docs const) does not say about type of mask in copyTo() function.