Ask Your Question

marcoE's profile - activity

2021-03-03 05:46:23 -0600 received badge  Notable Question (source)
2020-05-10 17:14:10 -0600 received badge  Popular Question (source)
2019-06-19 11:20:18 -0600 received badge  Notable Question (source)
2019-04-24 13:44:16 -0600 received badge  Famous Question (source)
2019-04-09 10:12:30 -0600 received badge  Popular Question (source)
2017-11-10 02:03:07 -0600 received badge  Popular Question (source)
2017-07-24 00:26:47 -0600 received badge  Notable Question (source)
2017-01-23 08:05:53 -0600 received badge  Popular Question (source)
2016-09-08 07:27:36 -0600 asked a question What are the "moments" in opencv ? Ratios, eigenvalues and eigenvectors

I asked this question : Question about second momentos, which @Tetragramm helped me a lot .

For me it's not clear how can I get the Second Moments of Area, I'm not sure what cv:moments returns, what "moments" .

#!/usr/bin/python
import cv2
import numpy as np

# mesh image
imMesh = cv2.imread('new_refined2__DXF.png', -1)
# layer image
imLayer1 = cv2.imread('Layer1.png', -1)
"""
binary conversions
"""
imMeshGray = cv2.cvtColor(imMesh, cv2.COLOR_BGR2GRAY)
ret, imMeshBw = cv2.threshold(imMeshGray, 250, 255, cv2.THRESH_BINARY)

imLayer1Gray = cv2.cvtColor(imLayer1, cv2.COLOR_BGR2GRAY)
(thresh, imLayerBw) = cv2.threshold(imLayer1Gray, 128, 255,
                                cv2.THRESH_BINARY | cv2.THRESH_OTSU)

cv2.imwrite('bwImlayer.jpg', imLayerBw)
connectivity = 4
output = cv2.connectedComponentsWithStats(imMeshBw, connectivity, cv2.CV_32S)
num_labels = output[0]
labels = output[1]
stats = output[2]
centroids = output[3]
file = open('moments_.txt', 'w+')
# if I want for each label
for label in np.unique(labels):
   if label == 0:
       continue
   mask = np.zeros(imMeshGray.shape, dtype="uint8")
   mask[labels == label] = 255
   maskedLayer = cv2.bitwise_and(mask, imLayerBw)

   M = cv2.moments(maskedLayer)
   m2 = cv2.moments(mask)
   Vr = float(M["m00"] / m2["m00"])

   if M["m00"] != 0:
       cX = int(M["m10"] / M["m00"])
       cY = int(M["m01"] / M["m00"])
   else:
        cX, cY = 0, 0

    file.write('{} {} {} {} {} \n'.format(Vr, M["m10"], M["m00"], cX, cY))
    cv2.putText(imMesh, "*",
                (cX, cY), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
file.close()
cv2.imwrite('tstCountoursConnected_3.jpg', imMesh)

The outputs: BwImLayer

OutputCountoursConnected

Output Text

Inputs :

source Imesh

Layer image

I think this peace of code:

cX = int(M["m10"] / M["m00"])

cY = int(M["m01"] / M["m00"])

calculates the centroids, because they are related to the masked layer, so the "centers" are not the center of the "triangles". I'm not sure !

I want to calculate eigenvalues and eigenvector of the second moments of area from the center of triangle. With this result I'll have the magnitude and the direction of the "piece of the layer" in each triangle which has something.

I think with this piece of code :

Vr = float(M["m00"] / m2["m00"])

I'm computing the ration between the "white" and "black". I've followed the @Tetragramm tip

2016-08-12 07:09:10 -0600 commented answer Calc the Seconds moments of area of huge number of countours

Ok, I think it is closer. This is my updated code: http://pastebin.com/u4WkuH40 and the outputs https://dl.dropboxusercontent.com/u/7... https://dl.dropboxusercontent.com/u/7... https://dl.dropboxusercontent.com/u/7... Is this right? Another Question, i want to calculate the % of white for each triangle ? The mask "cuts" the triangle contour.

2016-08-11 10:26:56 -0600 commented answer Calc the Seconds moments of area of huge number of countours
2016-08-11 08:11:11 -0600 commented answer Calc the Seconds moments of area of huge number of countours

imLayerBw is what your are saying :) https://dl.dropboxusercontent.com/u/7... Your code update doesn't have the contour code. Without the code to take the countour how can we get the moments ?

2016-08-11 07:24:26 -0600 commented answer Calc the Seconds moments of area of huge number of countours

Ok, I did an update http://pastebin.com/kaC8aVQu and the output is https://dl.dropboxusercontent.com/u/7... I think, something is missing, anyway ! But is close

2016-08-11 04:23:33 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm Thank you for your support. I think there is a litle thing to solve. This is the updated code, and I think that's what you've recommended http://pastebin.com/NpjDz7Yw Is not possible do the maskedLayer = cv2.bitwise_and(mask, imLayer1) , because they don't have the same dimensions, So I assumed that was maskedLayer = cv2.bitwise_and(mask, imLayerBw) , but it does not work either. I think this is the "litle thing" to solve. it is almost done !

2016-08-10 03:47:35 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm I didn't get it :) What bitwise stuff ? I know that i need some oeprations, but with so many comments and misunderstandings (of me ) I don't know what they are :) Anyway, I added features to my code, that I think with your help will be helpful. Code: http://pastebin.com/6TgZKXmD output: https://dl.dropboxusercontent.com/u/7...

2016-08-09 05:28:12 -0600 commented answer Calc the Seconds moments of area of huge number of countours

hi ! my current code : http://pastebin.com/PgucizcR This are my images https://dl.dropboxusercontent.com/u/7... https://dl.dropboxusercontent.com/u/7... But I have a problem. My "triangles" onde the layer are not "good" Because there black and white parts of the triangle, it depends on the geometry of the layer. Should I do other bitwise operation or use this image https://dl.dropboxusercontent.com/u/7...

2016-08-08 09:35:33 -0600 commented answer Calc the Seconds moments of area of huge number of countours

I think that I get it : http://pastebin.com/m6FJnQpi I have the handicap with this code. I'll only see the label 14, because it's the last of the set. But I can do for all of the components. What's the next step ?

2016-08-05 05:25:54 -0600 commented answer Calc the Seconds moments of area of huge number of countours

This is my example code : http://pastebin.com/WvPwebS8 How can I get just one triangle ? I'm tryng selec only the labels which are one and then write a image without success

2016-08-04 05:18:13 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm thx and I'll try. I think my problem is with "masks" and bitwise operations, to get the images that I want. But I'll do the "tests" anyway.

2016-08-03 04:34:16 -0600 commented answer Calc the Seconds moments of area of huge number of countours

Completly stucked . :\

2016-07-29 05:18:33 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm I understood what you said, but i'm not able to see the triangle or how to extract it. I'll look into the docs.

2016-07-28 05:33:13 -0600 commented answer Calc the Seconds moments of area of huge number of countours
2016-07-28 04:23:05 -0600 commented answer Calc the Seconds moments of area of huge number of countours

No, I don't know how many triangle do I have. However, I know that are lot of labels = 0, and labels =1 ; so I can assume that are triangles with the same label. I did the tresh = 250 .

2016-07-27 08:47:12 -0600 commented answer Calc the Seconds moments of area of huge number of countours

However there are more triangles than labels. For istance with label 0, it has 7884676 triangles. With the label 1, 19673, etc.

2016-07-27 08:09:51 -0600 commented answer Calc the Seconds moments of area of huge number of countours

I think that finally I get the correct connectComponents value, 13053 . I still don't know how to do what I need to do :)

2016-07-26 09:11:29 -0600 commented answer Calc the Seconds moments of area of huge number of countours

The highest number that I get of connect components labels is : 1740 and countours is : 172187 with this config : ret, imMesh_bw11 = cv2.threshold(imGrayMsh1, 128, 255, cv2.THRESH_BINARY) and I get this image: https://dl.dropboxusercontent.com/u/7...

2016-07-25 09:56:22 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm when I use _, contours, hier_ = cv2.findContours(imMesh_bw1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(colorMask,np.array(contours),-1,(0,0,255),6) it returns 125091 contours (probably the total number of triangles), and if I draw it, it returns this image : https://dl.dropboxusercontent.com/u/7... . Could this be an alternative? i'm not handling properly connectedComponents, I think.

2016-07-25 08:02:03 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm something is wrong. I look into the labels matrix. It's size is the same of the original image. However, they are 3079 different connectedComponents . If select according to the label value, I select a lot of triangles not only one.

2016-07-25 07:43:29 -0600 commented answer Calc the Seconds moments of area of huge number of countours

It seems odd to me. I have more than 3080 components. There are far more triangles.

2016-07-25 05:16:28 -0600 commented answer Calc the Seconds moments of area of huge number of countours

Ok, I think that I'm understanding what you are saying. This is my current code: http://pastebin.com/HfuGUD2N I have 3080 connectComponents. But I don't know how to deal with the information

2016-07-22 10:06:59 -0600 commented answer Calc the Seconds moments of area of huge number of countours

when I appy the ret, markers = cv2.connectedComponents(imMeshly_bw), with imMeshLayer = cv2.imread('testLayer6_.png', -1) imGrayMshLayer = cv2.cvtColor(imMeshLayer, cv2.COLOR_BGR2GRAY) (thresh, imMeshly_bw) = cv2.threshold(imGrayMshLayer, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) I got : https://dl.dropboxusercontent.com/u/7...

2016-07-22 05:59:40 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm you've said " Make a copy of your layer image and use bitwise_and with the single triangle to erase everything but what is inside that triangle." How can I select just one triangle for each time. I think that I'm understanding the process. Having n-masks, one for each triangle. Then for each mesh-triangle I can calc moments, centroids, etc . However. I don't get the "process" to reach it.

2016-07-21 03:57:48 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm the connectComponents function is not available in python :\ Any alternative, or I should just implement in C++ ? It won't be easy to me, I'm used to use opencv python

2016-07-20 08:19:18 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm is it something like this that is need to calc the moments per triangle? https://dl.dropboxusercontent.com/u/7...

2016-07-20 04:38:05 -0600 commented answer Calc the Seconds moments of area of huge number of countours

another alternative approach. If I have the mesh and the "layer" where the mesh is. Is it easier to isolate? Mesh image: https://dl.dropboxusercontent.com/u/7... Layer image: https://dl.dropboxusercontent.com/u/7... code: http://pastebin.com/Q3sN5akv

2016-07-19 05:19:44 -0600 commented answer Calc the Seconds moments of area of huge number of countours

@Tetragramm It's not easy. Should I keep all the mesh contours in white? Or some in white and others in black? Could I use other color to all mesh, and then calculate moments?

2016-06-20 05:03:49 -0600 commented answer Calc the Seconds moments of area of huge number of countours

link text I've cut a litle piece. I want to calculate the volumes and the second moments of intertia of each triangle. I've put some numbers just to have an example. So, the number 1 has 0% of Volume, it's empty, the seconds moments are null. The number 2 has 100% of volume, second moments would have big values. Number 3 would have 60% of volume more or less, and the second moments would be intermediate. Number 4 it's a big hole, I don't want to calc anything.

I think it's clearer what I'd like to calculate.

2016-06-20 05:02:01 -0600 received badge  Citizen Patrol (source)
2016-06-20 03:45:21 -0600 commented question Calc the Seconds moments of area of huge number of countours

@sturkmen , what is big ? :)

2016-06-17 05:29:26 -0600 asked a question Calc the Seconds moments of area of huge number of countours

Hello! Finally I was able to properly fit he mesh with the layer. For this image (7158x16392 8MB)

I need to calculate the percentage of blacks and browns per triangle, and also the seconds moments of area per triangle. I'm facing some problems. The mesh layer should always be the master. For instance, If I have a triangle with all black, it should return 100% empty and without second moments.

So, I'm facing some problems to find out the proper bit-wise function, which allows me to make the mesh being the "master", and then I don't know how to iterate over a such huge amount of contours and make the calcs. I think the second moments which are native supported by opencv are the seconds moments of inertia, not the second moments of area..

2016-06-06 05:48:31 -0600 commented answer How can I fit and then overlay 2 images which have different resolution ?

@theodore another question, that could be significant. Having the stl coordinates in numpy array, is it possible draw the mesh in opencv instead of using matplotlib to render it? I think it could reduce the errors between scale resolution

2016-06-06 05:42:38 -0600 commented answer How can I fit and then overlay 2 images which have different resolution ?

@theodore I agree with you. I was thinking if it would be better create at source image (the one which I use to generate the mesh) 3 or 4 points as guides, and then plot them on the mesh with the transformation and them draw them on the layer.

2016-06-06 05:03:17 -0600 commented answer How can I fit and then overlay 2 images which have different resolution ?

@theodore did you understand what my problem is? I think in a simple chat i could explain easily