I just got the IMX708 upgrading over the arducam v1.3. But I don't think my camera is autofocusing. Take a look.
![Image]()
versus my phone
![Image]()
It's the same lego piece.
I asked ChatGPT to do this for me.
Thoughts? I'm on a raspberry pi 4b with bookworm.

versus my phone

It's the same lego piece.
I asked ChatGPT to do this for me.
Code:
import cv2import numpy as npfrom picamera2 import Picamera2import timedef detect_object(frame, threshold_area=5000): # Convert to grayscale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Blur to reduce noise blurred = cv2.GaussianBlur(gray, (5, 5), 0) # Threshold the image to binary _, thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY_INV) # Find contours (shapes/blobs) contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # Check for large enough contours (filter noise) for contour in contours: area = cv2.contourArea(contour) if area > threshold_area: return True # Object detected return False # No significant objectdef sharpen_image(frame): kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) sharpened = cv2.filter2D(frame, -1, kernel) return sharpeneddef main(): picam2 = Picamera2() config = picam2.create_preview_configuration(main={"size": (640, 480)}) picam2.configure(config) picam2.start() picam2.set_controls({"AfMode": 2}) picam2.set_controls({ "AwbEnable": True, # Turn on AWB "AwbMode": 0 # 0 = Auto }) time.sleep(2) # Let the camera warm up print("Detecting objects. Press Ctrl+C to stop.") while True: frame = picam2.capture_array() frame = sharpen_image(frame) # ?? Apply sharpening here# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) if detect_object(frame): print("? Object detected!") config = picam2.create_still_configuration() picam2.capture_file("photo.jpg") print("Saved photo.jpg") time.sleep(1) picam2.stop() else: print("? No object.") # Optional: Show camera feed (comment out if headless) cv2.imshow("Camera", frame)# cv2.imshow("Camera View (Color)", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows() picam2.close()if __name__ == "__main__": main()Statistics: Posted by traderjoe — Fri Aug 08, 2025 10:04 pm