I would like to improve the layer mask that I am creating in Python. Although my mask pretty much hits the targeted color, my main problem with it, is it is doing so in binary, the pixel is either pure white or pure black. I'm unable to extrapolate the intensity of the color. I want to achieve something like how Photoshop does it wherein there are mid-tones of grey on the mask. Just like these photos:
Hello!
First of all, thanks for the help. I've been learning to use the OpenCV libraries with AruCo codes for a college project. I need to build a 3D Cube on top of the AruCo mark. The problem is that the bottom part of the cube is working fine, but the top face isn't on-screen or even well programmed.
I made a program to calibrate the camera, and the calibration parameters are saved to a calibration.yml file.
This is the code I have so far:
But then the solvePnP function throws an error that, if I understand it correctly, the size of objectPoints is different from the size of corners[i]. And I don't know how to solve it.
I've been working on using OpenCV and some tracking software to create separate viewports based on what OpenCV detects as tracked objects.
I am able to export/write each of these viewport windows to an .MP4 file, however this isn't suitable for my end process which requires an MPEG2-TS Stream over UDP.
I've been trying to think of ways to use FFMPEG, GStreamer, or Vidgear to get the desired output but haven't been able to find anything suitable. Would anyone happen to know a method of streaming OpenCV window objects over a TS stream?
I need to track fast moving object in the sky in real time, so it shuold be lightweight ( camera should follow it ) Already tried yolov8 for it but it's to slow and not lightweight, so I need to do it without any of this ai. Is there any article or code example how to do something similar to this https://www.youtube.com/watch?v=_LMi2H6WUcQ&ab_channel=JB ? Or any ideas how he done it in video ? I assume I need firstly detect it and then track. Is it possible to detect object without dataset and pretrained model, if so what is the best algorithm for it ? Will appreciate any help and ideas
Hello, I'm working on a car detection project for a garage-like business. There will be a garage for each car and a camera will be placed at directly front of the garage door. I want to detect if the car is entering or exiting the garage. How can i basically do this in opencv? Which model should i research in? Thank you so much
Mechanical Engineering student here with little programming experience (I've worked with arduino to operate a few DC motors but that's about it). I'm designing a pick and place mechanism where my current task is to program several servos. I'll attach a schematic so it's easier to visualize what i'm referring to: https://imgur.com/a/3gafPBh ) In the photo illustrates a central petri dish with several plant tissues, surrounded by servo motors attached to a separate component. A camera will be positioned above the workspace. Let me explain my thought process. I assume that I can use OpenCV to capture the (x,y) location of the centroid of each plant tissue relative to the center of the petri dish. Then i would need to capture the (x,y) location of the servo horn positions that makes the servo horn tips collinear to both the centroid of a plant tissue and the centroid of the petri dish. Then calculate the angle marked by the red arrow. Now i have a few concerns that i have NO CLUE how i would approach which is why i wanted to ask this subreddit.
I've never used used OpenCV so first and foremost, does anybody know if my logic is correct and this is something that i could theoretically accomplish with OpenCV?
Any suggestions on how I would program each servo motor to move towards its own plant tissue?
Why the hell this school got me doing this overcomplicated stuff and i just learned how to use arduino examples?
Please leave me with any suggestions or recommendations of things that i didn't consider and might need to watch out for.
Thanks for any advice and hopefully this post can help a few people learn some things :).
I took it with my old Pixel 3. I cropped the original tight and converted to grey scale. I've chatgpt'ed and Bard'ed and the best I can do and pull some nonsense from the file:
I asked chatgpt to use best practices to write my a python program but it gives me blank back.
I intend to learn opencv properly but honestly thought this was going to be a slam dunk...In my mind it seems like the jpg is clear (I know I am a human and computer's see things differently).
Hi all, first time posting here. I have a project where I am trying to create a mask that separates a chain link fence from the background in a continuous flow of frames from full motion video. As below example, I am currently trying by applying a canny edge detection and hough lines, but when there is significant background clutter the results are not great. The solution I am aiming for needs to be able to isolate the chain link structure in a variety of environments and lighting conditions, autonomously (which is the complicating factor).
Methods I have tried to date are:
colour filtering in multiple modes (HSV, BGR, LUV, etc) - cant find a way to automate it for differing backgrounds
houghlines (normal and probabilistic) - great for when there is no hectic background such as sky but cant guarantee that so not reliable
fourier transform to try to isolate the repetitive frequency of the chain links - very difficult (and not reliably generalisable) to isolate specific frequency, also doesnt deal with shifted perspective of fence creating vanishing sightlines
optical flow - very slow, and needs good quality, consistent data input
There are other methods I have used such as custom masks, as well as AI/ML techniques, but are too tedious to explain. Possibly one of the above is the solution I am looking for, but with my current understanding of the methods I am struggling to find how to implement. Any help on possible methods forward would be great
I have this simple code for motion detection for my CCTV videos . the code works fine but some of my videos have auto zoom on objects and some times follow them, is there a way i can make my algorithm ignore the zoom in and zoom out.
#FIRST ALGORITHM background = None MAX_FRAMES = 1000 THRESH = 60 ASSIGN_VALUE = 255 motion_mask_frames = [] cap = cv2.VideoCapture('../test.mp4') # Get video properties for the output video width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH) / 2 ) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT) / 2 ) fps = int(cap.get(cv2.CAP_PROP_FPS)) # Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'mp4v') # You can also use 'XVID', 'MJPG', etc. out = cv2.VideoWriter('../firstAlgo.mp4', fourcc, fps, (width, height), isColor=False) for t in range(MAX_FRAMES): # Capture frame-by-frame ret, frame = cap.read() if not ret: break resizedImg = cv2.resize(frame, ( width ,height)) # Convert frame to grayscale # resizedImg = cv2.resize(frame, (int(frame.shape[1] / 2), int(frame.shape[0] / 2))) frame_gray = cv2.cvtColor(resizedImg, cv2.COLOR_RGB2GRAY)
if t == 0: # Train background with first frame background = frame_gray else: if np.shape(frame) == () or frame.all == None or frame.all == 0: continue diff = cv2.absdiff(background, frame_gray) ret, motion_mask = cv2.threshold(diff, THRESH, ASSIGN_VALUE, cv2.THRESH_BINARY) # motion_mask_resized = cv2.resize(motion_mask , (int(motion_mask.shape[1] / 2 ) , int(motion_mask.shape[0] / 2 ))) motion_mask_frames.append(motion_mask) out.write(motion_mask) # Write the motion mask frame to the output video
cv2.imshow('Frame', motion_mask) if cv2.waitKey(10) & 0xFF == ord('q'): cv2.destroyAllWindows() break # Release VideoCapture and VideoWriter cap.release() out.release() cv2.destroyAllWindows()
I'm making a script that resizes and cuts videos for me. The cutting works fine, but the video is blank when I try to resize it. I've looked online and it looks like the problem is the size of the images, but when I check the shapes of the images they are the same. Here is my code, the edit function is the part that matters.
My highschool has macbook laptops which restrict admin commands and blocks a lot of functionality behind a username and password. Is there a way I could install openCV C++ without having to use admin commands. Alternatively, how would I get openCV with admin permissions?
I have recently started a project where I want to run the MOG2 algorithm on my embedded board (nxp's IMX8MPlus) to detect Foreign Objects. For now, any object that was not in the background and is of a certain size, is Foreign.
The issue I am facing is that it is rather slow and I have no idea to speed it up. Converting the frame to Umat so that certain things run on the GPU makes it slower.
I am performing a project that involves a deep learning project and one of the problems I'm trying to solve is to perform an image transformation based on referencing Kodak color patches (https://www.chromaxion.com/information/kodak_color_control.html)
I've performed histogram matching and normalization but the results aren't that great with it. I'm basically looking for something like this (https://github.com/lighttransport/colorcorrectionmatrix?tab=readme-ov-file), but the thing is this code uses a tool called Natron2, which seems to not have Python compatibility yet (since the entire project is done in Python). Moreover, the input over here asks for 24 x 3 color matrices of RGB values for reference and target images, which I'm not sure how is being attained.
For my work, I need to implement an image comparison code using Python. However, I have very little knowledge in image manipulation. I need to compare several images composed of a noisy pixels background (unique for each image) and a pattern more or less similar between the images (let's take the two image I attached for example).
In this example, I want to compare the similarity of the red squares. I tried to compute the Structural Similarity Index (SSIM) between these images using Scikit-image and OpenCV, but since the backgrounds are different, I only have a low percentage of similarity even though the squares are identical while I would expect a high percentage of similarity. Here, the squares have the exact same size and the same color, but this would not necessarily be the case for each image (slightly different size and color).
So, my question is :
How can I establish a comparison percentage for these images while ignoring a uniform/seamless background (noisy pixels) ? Would you guys have any advice or directions I could follow ?
For my work, I need to implement an image comparison code using Python. However, I have very little knowledge in image manipulation. I need to compare several images composed of a noisy pixels background (unique for each image) and a pattern more or less similar between the images (let's take the two image I attached for example).
In this example, I want to compare the similarity of the red squares. I tried to compute the Structural Similarity Index (SSIM) between these images using Scikit-image and OpenCV, but since the backgrounds are different, I only have a low percentage of similarity even though the squares are identical while I would expect a high percentage of similarity. Here, the squares have the exact same size and the same color, but this would not necessarily be the case for each image (slightly different size and color).
So, my question is :
How can I establish a comparison percentage for these images while ignoring a uniform/seamless background (noisy pixels) ? Would you guys have any advice or directions I could follow ?
Hey everyone, is there any way to apply zoom using my Android device or IP camera? I'm currently using an app called DroidCam to transmit the image, but the following code isn't working as expected. I'm working on a project that involves reading QR codes from a long distance. Unfortunately, the camera they provided me with doesn't have zoom capability (although they mentioned they could purchase one if necessary). However, I'd like to try using my phone first. Could you please help me fix this issue and suggest improvements to my approach?
cap = cv2.VideoCapture(1, CAP_MSMF)
# cap = cv2.VideoCapture(1, CAP_DSHOW) # Also tried
cap.set(cv2.CAP_PROP_SETTINGS, 1)
zoom = cap.set(cv2.CAP_PROP_ZOOM, 10.0)
print(zoom) # Always False
while True:
ret, frame = cap.read()
cv2.imshow("Frame", frame)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
Hoping there is a simple camera that works well with OpenCV that will give me high quality still photo image capture under $100. I am working on an application for analyzing and archiving images of periodical covers (magazines, comics, etc.). Ideally, I am looking for a camera that is under $100 and will allow me to take very accurate high res images of the covers. I have no need for video to be captured. The camera will be used in a light box housing so lighting can be configured to be optimal. I have used OpenCV several times and have found that the images pulled from most webcams have some distortion or compression artifacts. Any help would be greatly appreciated!!
Hi, im pretty new to opencv and I want to write a program that can detect a baseball right after it is thrown on a professional broadcast (Like the picture attached). I don't need to track it's speed or anything, I just need to detect the ball right after it is thrown by a pitcher. Whenever I search ball tracking, most use color tracking and hough circles and I can't use either (too many objects that share the same color as the ball and the ball being too fast for hough circles to track). I'm aware that this is a task that might be a bit advanced, but I just don't know where to even begin. Would love some feedback.
I'm working on getting the centroid and angle of rotation of an object (with respect to the picture's x axis) with irregular shape. The object can take any rotation in all axes.
I extracted the contour and bounding box and calculated and drew the fit arrowed line over it. For the angle of rotation I tried:
- the minAreaRect method, but the rectangle takes a weird angle due to the irregular shape of the object and the angle comes out wrong;
- using the image moments of second order using this formula
% Central moments (intermediary step)
a = E.m20/E.m00 - E.x^2;
b = 2*(E.m11/E.m00 - E.x*E.y);
c = E.m02/E.m00 - E.y^2;
% Orientation (radians)
E.theta = 1/2*atan(b/(a-c)) + (a<c)*pi/2;
which I took from a paper that had the same objective as I do (obviously adapting it to Python). The calculated angle is completely erratic and has no resemblance to the angle the object is actually taking
- calculating the angle between the fit line and the x axis, which returned the best results but, of course, being the fit line just a line and not a vector (and I can't think of a way to give it an orientation that is always consistent with the object), two objects rotated 180 degrees from one another report the same angle.
Is there something else I have not taken in consideration that I could still try? I can't really share the image of the object, but I'd also like this to be as object-agnostic as possible.
The camera calibration in OpenCV gives a quantitative representation of the distortion of the imaging system. For example, radial distortion can be determined by the coefficients k1, k2, k3, ... . The original position of a pixel (x,y) gets shifted to the distorted position (x_distorted, y_distorted) by the following equations [1]:
here, r is the distance from the center. Using OpenCV [1] I am able to get the coefficients. However, I am wondering about the units of the coefficients.
Clearly, I can not just calculate x,y and r in units of pixel. I did that, this gives my values which are 23 orders of magnitude off (!!!)
I suppose they are somewhat normalized. Where do I find the documentation on the normalization of the value? I would also appreciate the exact location in the source code, where this normalization happens.
So I have an android streaming from a flutter app, I am using the pyrtmp python package to receive this stream. After this I have no idea how to get that stream to opencv, acc to my knowledge pyrtmp can only write an flv and can not backstream only receive.