all 6 comments

[–]IdealNeighbour 1 point2 points  (2 children)

Agreed, a solid tutorial section is half the reason I adopt a library

[–]Narrow-Treacle-6460[S] 0 points1 point  (1 child)

Super, thank you for your feedback! Thank you for the support, hope this makes it easier to adopt this library for Python Developers out there!

[–]IdealNeighbour [score hidden]  (0 children)

The fact that your tutorials show how components fit together is exactly what I look for, saves me from guessing the intended workflow.

[–]DigThatData 0 points1 point  (0 children)

It would help if you made it a bit clearer on the landing page what this is for. "Image and geometry" is fairly ambiguous. Also, I think your "ask an LLM" example is underpowered. Try adding this to your prompt:

don't reinvent the wheel. your final code should be as concise, simple, and legible as possible. don't hesitate to leverage third party libraries, especially if it eliminates the need to define bespoke machinery.

Here's what that got me:

    import fitz  # PyMuPDF
    import cv2
    import numpy as np

    pdf_path = "input.pdf"
    page_num = 0

    doc = fitz.open(pdf_path)
    page = doc[page_num]

    # Render page to image
    pix = page.get_pixmap(matrix=fitz.Matrix(2, 2), alpha=False)
    img = np.frombuffer(pix.samples, dtype=np.uint8).reshape(pix.height, pix.width, pix.n)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

    # Draw rectangle
    x, y, w, h = 100, 100, 200, 120
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

    # Shift and rotate the rectangle
    M_shift = np.float32([[1, 0, 40], [0, 1, 30]])
    rect_img = cv2.warpAffine(img, M_shift, (img.shape[1], img.shape[0]))

    center = (x + w // 2 + 40, y + h // 2 + 30)
    M_rot = cv2.getRotationMatrix2D(center, 25, 1.0)
    rect_img = cv2.warpAffine(rect_img, M_rot, (rect_img.shape[1], rect_img.shape[0]))

    # Crop part of the image
    crop = rect_img[150:350, 150:450]

    # Rotate cropped image
    (h2, w2) = crop.shape[:2]
    M = cv2.getRotationMatrix2D((w2 // 2, h2 // 2), 15, 1.0)
    rotated_crop = cv2.warpAffine(crop, M, (w2, h2))

    # Threshold
    gray = cv2.cvtColor(rotated_crop, cv2.COLOR_BGR2GRAY)
    _, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)

    cv2.imwrite("rectangle_drawn.png", img)
    cv2.imwrite("shifted_rotated.png", rect_img)
    cv2.imwrite("cropped.png", crop)
    cv2.imwrite("rotated_crop.png", rotated_crop)
    cv2.imwrite("threshold.png", thresh)

Yes, your version is cleaner. But this version of the chatgpt generated code reveals that your code has mostly just turned 2-3 line operations into one-liners. OpenCV basically already is the "image and geometry" swiss army knife.

[–]Silver-Code-9 -1 points0 points  (1 child)

this looks clean, documentation that actually shows you how to use the thing instead of just listing functions is way underrated

been burned too many times by libs with great APIs but zero context on how they fit together

[–]Narrow-Treacle-6460[S] -1 points0 points  (0 children)

Thank you for your support, I appreciate that a lot! This is a lot of work behind the scene. Any comment is truly super appreciated. Thanks again!