help me figure out why this isnt working as intented, it's suppose to look on the left…
- User
help me figure out why this isnt working as intented, it's suppose to look on the left side of the cropped image and react when there's a black dot showing, but it just says "The two images have different sizes The two images have different sizes" "The cropped frames are empty" "Not found":
def check_for_dot(frame, previous_frame, x, y, w, h, threshold): # Convert the image to grayscale current_frame = frame.copy()
# Check if the two images have the same size if current_frame.shape != previous_frame.shape: print("The two images have different sizes") return "Not found" # Check if the two images have the same number of channels if current_frame.ndim != previous_frame.ndim: print("The two images have a different number of channels") return "Not found" # Crop the images to the specified area current_frame = current_frame[y : y + h, x : x + w] previous_frame = previous_frame[y : y + h, x : x + w] # Check if the cropped frames are not empty if current_frame.size != 0 and previous_frame.size != 0: # Convert the image to grayscale current_frame = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY) previous_frame = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY) else: print("The cropped frames are empty") # Compute the absolute difference between the current frame and the previous frame frame_diff = cv2.absdiff(current_frame, previous_frame) # Convert the difference image to binary _, binary_diff = cv2.threshold(frame_diff, 10, 255, cv2.THRESH_BINARY) # Count the number of black pixels num_black_pixels = cv2.countNonZero(binary_diff) # Check if the number of black pixels is above the threshold if num_black_pixels > threshold: print("Found it") return "Found it" else: print("Not found") return "Not found"x, y, w, h = 100, 100, 200, 200 threshold = 400
@app.post("/capture_image") async def capture_image(): global SERVER_RESPONSE previous_frame = None
# Adjust the green color range green_lower = np.array([1, 177, 115], np.uint8) green_upper = np.array([85, 255, 255], np.uint8) # Load image from file instead of camera url = "http://192.168.229.55:8080/shot.jpg" while True: img_resp = requests.get(url) img_arr = np.frombuffer(img_resp.content, np.uint8) frame = cv2.imdecode(img_arr, -1) # Convert the image from BGR to HSV color space hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # Create a binary mask where white represents the green color green_mask = cv2.inRange(hsv, green_lower, green_upper) # Apply morphological operations to reduce noise kernel = np.ones((5, 5), np.uint8) green_mask = cv2.dilate(green_mask, kernel, iterations=1) green_mask = cv2.erode(green_mask, kernel, iterations=1) # Find contours in the green mask contours, _ = cv2.findContours( green_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE ) if len(contours) != 0: max_contour = max(contours, key=cv2.contourArea) x, y, w, h = cv2.boundingRect(max_contour) # Ensure the coordinates are in the correct order cropped = frame[y : y + h, x : x + w] # Calculate the area of the largest contour green_area = cv2.contourArea(max_contour) # Check if the detected green area is of a certain size AREA_THRESHOLD = 5000 # adjust this value based on your requirement if green_area > AREA_THRESHOLD: # Check if the directory exists, if not create it if not os.path.isdir("images"): os.mkdir("images") # Save the image height, width = cropped.shape[:2] if width < height: cropped = cv2.rotate(cropped, cv2.ROTATE_90_CLOCKWISE) # Ensure the coordinates are in the correct order cropped = frame[y : y + h, x : x + w] # Check if the cropped frame is not empty if cropped.size != 0: # Check if this is the first frame if previous_frame is not None: # Check if the sizes of the current frame and the previous frame are the same if cropped.shape == previous_frame.shape: # Check for dot result = check_for_dot( cropped, previous_frame, x, y, w, h, threshold ) if result == "Found it": print("Changed") cv2.imwrite("images/captured_image2.jpg", cropped) result = check_picture("images/captured_image2.jpg") SERVER_RESPONSE = result[0] await generate_audio() return result else: print("The two images have different sizes") # Store current frame as previous frame for next iteration previous_frame = cropped.copy() # Display the resulting frame cv2.imshow("Frame", cropped) # Press Q on keyboard to exit if cv2.waitKey(1) & 0xFF == ord("q"): break else: print("The cropped frame is empty") return "Not found" - Assistant
- User
suggest ways to fix all of them for me with code
- Assistant
- User
what is the easiest way to extract a window from a video? the color way I'm doing is too dependet on the lightning
- Assistant
- User
- Assistant
- User
So I want it to continue looping and I will have another template check to see if a dot is visable or not and if it is then it will take the photo and send it to the function that will look at the numbers in the picture
- Assistant
- User
so how do I start it now?
- Assistant
To start the image processing using the FastAPI application, you'll need to follow these steps:
-
Make sure all placeholder functions and paths (
check_picture,path_to_window_template.jpg,path_to_dot_template.jpg, etc.) in your script are replaced with actual, working code and file paths.
-
- User
- Assistant
The error message you received indicates that a
TypeErroroccurred because aNonewas passed as an argument to thefloat()conversion, which meansSERVER_RESPONSEwasNoneat that moment. This likely happened in theupdate_csv()function or in thegenerate_audio()function when you attempted to convert the response to a float: - User
- Assistant
To display the frames that the webcam is capturing, you can use OpenCV's
cv2.imshow()function to create a window and display the frame. You've already included the line in your function, but in order to update the display and allow OpenCV to process window events (like closing the window), you also need to call periodically. Here's a modified snippet of your function with these updates:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.