0

I Cylinder to straight lines

I have a cylindrical object which is being looked at from a sideways perspective. I know the pixel locations on the sides of the lines. How can I straighten these lines?

I have drawn a small example image.

edit: attached real example: points order is top left - top right, second top left - second top right etc enter image description here

import cv2
image = cv2.imread('image.jpg')
points  = [[946, 721],[1814, 864],[934, 729],[1806, 874],[934, 729],[1806, 874],[923, 737],[1798, 885],[923, 737],[1798, 885],[912, 745],[1790, 896],[912, 745],[1790, 896],[900, 755],[1781, 909],[900, 755],[1781, 909],[889, 764],[1773, 922],[889, 764],[1773, 922],[877, 775],[1764, 936],[877, 775],[1764, 936],[866, 786],[1755, 951],[866, 786],[1755, 951],[854, 798],[1746, 966],[854, 798],[1746, 966],[843, 810],[1737, 983],[843, 810],[1737, 983],[832, 823],[1728, 1000],[832, 823],[1728, 1000],[820, 836],[1719, 1017],[820, 836],[1719, 1017],[809, 850],[1710, 1036],[809, 850],[1710, 1036],[798, 865],[1700, 1055],[798, 865],[1700, 1055],[787, 880],[1691, 1075],[787, 880],[1691, 1075],[777, 896],[1681, 1095],[777, 896],[1681, 1095],[766, 912],[1672, 1116],[766, 912],[1672, 1116],[756, 929],[1663, 1138],[756, 929],[1663, 1138],[745, 946],[1653, 1160],[745, 946],[1653, 1160],[735, 963],[1644, 1183]]

circles_image = image.copy()

for point in points:
    circles_image = cv2.circle(circles_image, (int(point[0]), int(point[1])), 1, (255, 255, 255), 12)
    cv2.imshow("test_img", mat=circles_image)
cv2.waitKey(0)

It will look like this enter image description here

Osi
  • 406
  • 3
  • 13
  • do you have a camera matrix or would you like to assume an orthographic projection instead? – Christoph Rackwitz Apr 14 '22 at 10:47
  • @ChristophRackwitz it's an ortographic projection. Perfect accuracy is not required, just having the majority of the image straight is fine. – Osi Apr 14 '22 at 11:27
  • ok, reformulating the problem: you want the *texture* of that cylinder. that's the rectangular picture on the right. -- first, *somehow* define the pose of the cylinder relative to the camera. pick some points on its end face ellipses. you need to be able to define an arbitrary point on the cylinder's surface, transform from cylinder frame to camera frame, and then project that 3D point into the view (left side)... to sample the view. -- now you can, for every pixel of the texture, calculate its coordinate on the cylinder, transform into camera space, project, and sample the view image. – Christoph Rackwitz Apr 14 '22 at 11:39
  • some real data would help... the sketch is imperfect, not usable as data. – Christoph Rackwitz Apr 14 '22 at 11:48
  • @ChristophRackwitz I've added some real photos with real points. – Osi Apr 14 '22 at 13:28
  • I fitted some ellipses through that picture. it's a perspective projection, not orthographic. that will make the math less simple but within what I described. you'll need to implement a few things to do this, of course. -- you'll want to calibrate the camera and add the values to your question. knowing the camera matrix is vital to getting correct results from solvePnP... and so is knowing the dimensions of the cylinder (specifically the diameter and spacing of the circles, in space) – Christoph Rackwitz Apr 14 '22 at 15:43
  • I've got a proof of concept but the results are noticeably imperfect. I'll need accurate values for the camera matrix, diameter of the cylinder, and distances along the cylinder for all the edges. and if you post screenshots, please crop them precisely so they match the camera image dimensions, or simply `imwrite` (or try Ctrl+S) the image you gave to `imshow` (that's data then, not just an illustration). – Christoph Rackwitz Apr 14 '22 at 16:06
  • related: https://stackoverflow.com/questions/72596841/dewarping-an-image-of-a-curved-bottle-surface – Christoph Rackwitz Jun 13 '22 at 07:00

0 Answers0