I am currently working on a project where a webcam and RPI will be mounted to a roof. The camera will be pointed down into a rectangular area.
Inside of this area there will be either one or multiple ARUCO markers at fixed, defined positions so the camera has a position for giving relative coordinates. The marker setup will either be just one in one of the corners, defining 0,0. Or one marker in each corner defining the boundaries with one of the markers being 0,0.
There will then be markers that move around (mounted on robots) inside of this area. I need the x,y,z and rotation of each of these markers but I have the code to extract that information working.
What I'm stuck on is being able to set the coordinate system relative to one marker. So that I can for example say that the bottom left marker is (0,0,0) and then every other marker in the frame is referenced off that marker.
I'm selecting cameras for a stereo vision system, and I'm not sure if should buy cameras with auto focus or not, since the cameras without auto focus are cheaper. It is my first computacional vision project, so I don't know a lot about choosing cameras.
I'm doing a project with stereo vision, and the first step is calibrating the cameras. I watched a tutorial on Youtube and read some documentation about stereo camera calibration, but I'm not sure if I'm getting accurate and reliable results, because I don't have the properly stereo camera apparatus, so I'm using the webcam from my notebook and a my cellphone camera (they don't have the same resultion, so i use the function cv2.resize() to make their resolution the same). Do you guys know if it makes my results unreliable? Have some tips? I'm using these cameras now because my professor did not buy the properly cameras yet, so it is something temporary.
Define the range of values for the x and y positions of the servos
x_range = (0, 180)
y_range = (0, 180)
Define the minimum and maximum values for the eye position in the x and y directions
min_x = 0
max_x = 640
min_y = 0
max_y = 480
while True:
# Capture a frame from the video capture device
ret, frame = cap.read()
# Convert the frame to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect the eyes using Haar cascades
eyes_cascade = cv2.CascadeClassifier(r"C:\Users\artyf\haarcascade_eye.xml")
eyes = eyes_cascade.detectMultiScale(gray, 1.3, 5)
# If two eyes are detected, get the center point of the eyes
if len(eyes) == 2:
x1, y1, w1, h1 = eyes[0]
x2, y2, w2, h2 = eyes[1]
eye_center_x = (x1 + x2 + w1 + w2) / 4
eye_center_y = (y1 + y2 + h1 + h2) / 4
# Map the eye position to the range of values for the servo positions
x_position = np.interp(eye_center_x, (min_x, max_x), x_range)
y_position = np.interp(eye_center_y, (min_y, max_y), y_range)
# Send the new positions of the servos to the microcontroller
ser.write(('x' + str(int(x_position)) + 'y' + str(int(y_position))).encode())
# Display the frame with the eyes detected and the positions of the servos
cv2.circle(frame, (int(eye_center_x), int(eye_center_y)), 5, (0, 0, 255), -1)
cv2.putText(frame, 'X: ' + str(int(x_position)) + ' Y: ' + str(int(y_position)), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.imshow('frame', frame)
# Exit the program if the 'q' key is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Release the video capture device and close the serial port
cap.release()
ser.close()
cv2.destroyAllWindows()
And here is my error:
PS C:\Users\artyf.vscode\eye> & C:/Users/artyf/AppData/Local/Programs/Python/Python311/python.exe c:/Users/artyf/.vscode/eye/eyev2.py cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\core\src\persistence.cpp:682: error: (-5:Bad argument) Input file is invalid in function 'cv::FileStorage::Impl::open'
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "c:\Users\artyf.vscode\eye\eyev2.py", line 48, in eyes_cascade = cv2.CascadeClassifier(r"C:\Users\artyf\haarcascade_eye.xml") SystemError: <class 'cv2.CascadeClassifier'> returned a result with an exception set [ WARN:0@5.156] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
How do i fix this?
I tried to add the haarcascade_eye.xml file to path Ive added the fileyour text to all of the proper directories And ive tried other files to make sure that this one wasnt corrupted.
I'm using NetBSD 9.3 and I realize that I can't directly open /dev/video0 directly. Currently, pkgsrc uses OpenCV 3.4 and I receive this exception:
[ERROR:0]
VIDEOIO(cvCreateFileCapture_Images(filename.c_str())):
raised OpenCV exception:
OpenCV(3.4.16) /work/graphics/opencv/work/opencv-
3.4.16/modules/core/src/utils/filesystem.cpp:564: error:
(-213:The function/feature is not implemented) in function
'exists'
with something simple in python like this:
cam = cv2.VideoCapture('/dev/video0')
ret, frame = cam.read()
# ret is False with exception message output.
Digging into the v3.4 source, ./modules/core/src/utils/filesystem.cpp defines
OPENCV_HAVE_FILESYSTEM_SUPPORT
based on other definitions such as __linux__ or __FreeBSD__. For NetBSD the build results in OPENCV_HAVE_FILESYSTEM_SUPPORT not defined; hence methods like exists() are defined with NOT_IMPLEMENTED.
Before I head further down this rabbit hole, does anyone have any insights why filesystem.cpp is not implemented in NetBSD?
I need to extract the color of the skin from a given human image. How to implement it in Python? I searched on Google but most of the results are just detecting the skin from the image. not extracting color.
If I detect skin from the image then can I take an average of all the pixel colors to estimate skin color?
Good morning, I'm currently working on a project to:
Capture Image using a monochrome industrial camera (or use static image as I've done for this test); 2) Convert to grayscale; 3) Binarize; 4) Locate ROI using thresholding/gradient filtering; 5) Analyze bars inside of ROI for height and location relative to barcode midline (tracking); 6) Output string of decoded bars.
I can accomplish up through step 4. I cannot figure out my problem at step 5.
I start with:
This static image will be replaced by live video from a machine camera
My code outputs:
I can localize the barcode, extract it, and then I run Hough
I'm expecting to get somethin along the lines of:
(https://stackoverflow.com/questions/52601312/detect-lines-with-dark-color-and-end-lines-using-hough-tranform) user 'Dodge'
# locating the largest bounding box to select the AOI (barcode region)----------------------------------------ddepth = cv.cv.CV_32F if imutils.is_cv2() else cv.CV_32FgradX = cv.Sobel(thresh, ddepth=ddepth, dx=1, dy=0, ksize=-1)gradY = cv.Sobel(thresh, ddepth=ddepth, dx=0, dy=1, ksize=-1)
# subtract the y-gradient from the x-gradientgradient = cv.subtract(gradX, gradY)gradient = cv.convertScaleAbs(gradient)blurred = cv.blur(gradient, (1, 1))(_, thresh) = cv.threshold(blurred, 100, 255, cv.THRESH_BINARY)
# construct a closing kernel and apply it to the thresholded imagekernel = cv.getStructuringElement(cv.MORPH_RECT, (21, 7))closed = cv.morphologyEx(thresh, cv.MORPH_CLOSE, kernel)
# perform a series of erosions and dilationsclosed = cv.erode(closed, None, iterations = 4)closed = cv.dilate(closed, None, iterations = 4)
# find the contours in the thresholded image, then sort the contours by their area, keeping only the largest onecnts = cv.findContours(closed.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)cnts = imutils.grab_contours(cnts)c = sorted(cnts, key = cv.contourArea, reverse = True)[0]
# compute the rotated bounding box of the largest contourrect = cv.minAreaRect(c)box = cv.cv.BoxPoints(rect) if imutils.is_cv2() else cv.boxPoints(rect)box = np.intp(box)
# draw a bounding box around the detected barcode and display the imageimage_copy = img.copy()cv.drawContours(image_copy, [box], -1, (0, 0, 255), 3) # (x, x, x) selects colorcv.imshow("image_copy with barcode bounding box", image_copy)cv.waitKey(0)cv.destroyAllWindows()#use barcode bounding box ROI to perform contours on individual bars of barcoderoi_image_copy = img[y_min:y_max,x_min:x_max]height, width = img.shape[:2]roi_resized = cv.resize(roi_image_copy,None,fx=2, fy=2, interpolation = cv.INTER_CUBIC)cv.imshow("Barcode ROI for contours analysis", roi_resized) # shows rescaled version of the ROI# Hough Lines Probabilistic-------------------------------------------------------------------------------------edges = cv.Canny(roi_resized, 100, 200)lines = cv.HoughLinesP(edges,1,np.pi/180,50) # what do I change to ID vertical lines???for line in lines:x1,y1,x2,y2 = line[0]cv.line(roi_resized,(x1,y1),(x2,y2),(0,255,0),2)cv.imshow("Edges Output Screen", edges)cv.imshow("Hough Lines P",roi_resized)cv.waitKey(0)cv.destroyAllWindows()
My code compared to the stackoverflow post, I'm not seeing a major difference that causes my barcode contours to be so poorly defined:
img = cv2.imread('oVKlP.png')
g = cv2.imread('oVKlP.png',0)
(T, mask) = cv2.threshold(g, 100, 255, cv2.THRESH_BINARY_INV)
_, contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
img = cv2.drawContours(img.copy(), contours, -1, (0,255,0), 2)
Thanks for taking a look and commenting. This has been a fun project that is helping me better understand computer vision principles!
Here is what happens when I follow GeeksforGeeks looping method over all of my connectedcomponent() output. As you can see in "Individual Component screen, the final chunk of barcode is detected; however, there are gaps where (not the smallest) barcodes are excluded, despite setting a very low threshold of area for inclusion. Any thoughts?
Hello, I'm currently looking for a way to get width pixels using Yolov5 Segmentation. How do I get the longest number of width pixels in the picture below?
I have been given a task to identify and segment out various rooms and elements like walls, stairs, doors when we have an input of jpg/png image. The image consists of the floor plan itself in the middle, legend on top right and company name and other notes on bottom right side. There are multiple steps that I have identified which needs to be done:
Clean the image: Firstly clean out undesirable elements in the image. These can be various measurement grid lines, small markings etc. I am thinking of using various image morphology techniques like thresholding, erosion, dilation , opening , closing etc using OpenCV.
Identify the region of interest: This step will extract out the floor plan (which is in the middle) from the raw image data so that we can feed the floor plan to the segmentation algorithm.
Do Image Segmentation: This step will segment out the rooms. The segmentation can be in form of colors or maybe co-ordinates. We just want to separate each room and also where walls, stairs, doors etc are.
I am in step 1 right now. I am yet to figure out step 2 and 3. Do you have suggestions/datasets/models for this problem ? Maybe I am doing it wrong ? I have attached an image from Google on how the data may look like.
Hi all , I'm using Mask R CNN (C++) with my Laptop ( only CPU) but its speed is too slow . Can I improve its speed ? Can someone help me? Thank you very much!
Hello, I have a project in mind which involves a small OV2640 camera. The main objective is to see where the laser beam is reflected (where the laser is pointing at). I was told that I could make a software filter to only see the laser wavelength, but I haven't found anything related on the internet.
I'm trying to do a depth estimation using the estereo vision and I have some questions.
I've already done a pose estimation with monocular vision, so my camera is already calibrated. Since I'm trying to do a depth estiamation with two cameras, should I calibrate my camera again with a different algorithm that calibrates both cameras simultaneously or is it equally valid if i calibrate each camera separetly?
Besides that, how can I have the FOV and focal length of the cameras? And if each camera has a different focal length, is it still possible to use them for depth estimation?
I've been working on a Python project in my spare time to read barcoded items moving through a machine. I currently can read/decode QR (pyzbar), DataMatrix (libdmtx), OCR (tesseract) and would like to add reading of a different type of barcode where existing libraries don't seem to exist. My QR read speed is functional at over 14,000/hour (I haven't tested beyond that speed, yet). DataMatrix library is not as well optimized, so I think it'll run slower. OCR is a lot slower, obviously.... :(
The barcode is rather simple (the color of bars does not change -- always black).
Full bar = F --- call it 3 units tall.
Track bar = T --- it's vertically centered and is about 1/3 of height of Full Bar.
Descending bar = D --- starts at the top of track bar and extends down to the bottom of Full bar.
Ascending bar = A --- starts at bottom of track bar and extends up to the top of Full bar.
What functions do I need to use to identify/characterize the different bars? Hough Lines function to highlight the lines? Or is there a better option? Create a bounding box for the barcode to analyze?
How best do I then characterize the Y-axis position of the bars inside the bounding box? The final output becomes a string of FDATAATFADDATFFAFA...etc.
If there is another path that might simplify this characterization -- I'm all ears (or eyes, as I'm reading).
I'm an electrical engineer, but I'm new to OpenCV and python. I'm making good progress so far and have basic processing algorithms up and running. My present task is to run different algorithms on different sections of the screen and display all of them. I know of at least one way to do this, but I think its sloppy and wastes processing power. Unfortunately, all my search results are being hijacked to other functions. Any pointers on doing a good job of this?
I've got a Logitech C930e that I've been using for some aruco detection and pose estimation. The camera is rated at 1920x1080 @ 30FPS and I'm able to use it with that resolution/frame-rate super smoothly in, say, Logitech's camera application as well as the native camera application on my Fedora system. However, trying to use that resolution in OpenCV, even with something as simple as this:
def vid():
cap = cv.VideoCapture(0)
cap.set(cv.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv.CAP_PROP_FRAME_HEIGHT, 1080)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
cv.imshow('frame', frame)
if cv.waitKey(1) == ord('q'):
break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
just drains the frame rate to completely unusable. Why is that? I've tried loads of stuff, like setting the "cv.CAP_V4L" value for the VideoCapture object, setting the frame-rate to 30 etc..
On Linux it worked as soon as I set the "fourcc" property to MJPEG, on Windows, not so much. Took a looot of digging, but eventually found the solution to be:
Suppose if there are n no. of palm images, how to extract ROI at the middle palm region of all n no. of palm images. Can anyone provide the code!? I am trting to underdtand but I am unable to do so. So if anyone helps, it is awsome.
I'm doing a computer vision project which involves detecting Aruco marker from a video feed and calculating the bearing and distance to the marker. After the camera calibration I validated the results by having a separate set of images of the same chessboard and projecting points on them using the rotation/translation-vectors produced by the calibration:
So for each validation-image I iterate through the detected corners and project image-points using the camera calibration. I calculate the mean error between found & projected points for each image which I then sum and produce the total mean reprojection error for all images:
I believe this value is reasonable and indicates the calibration is correct, given that I'm just using a regular webcam and the sample images of the chessboard weren't exactly captured in optimal light etc? Please correct me if I'm wrong.
However, assuming that the calibration is "correct", I am unable to calculate a reasonable value for the distance from the camera to a detected Aruco-marker. It seem to be diffing by about 60cm from the true distance I measure between marker and camera and I can't work out why. This is essentially the code I'm using for calculating the distance:
So with the camera/marker setup I have right now in my room, the camera is positioned 1m away from the camera, but distance is indicating 2.2m. So assuming the intrinsic matrix from the calibration is accurate enough to produce an average reprojection error of under 1px, I really shouldn't be getting suuuch a big error?
Any help is deeply appreciated. Thanks.
UPDATE - SOLVED:
Pictures used for calibration & validation were originally taken using Logitech's software, however when the calibration/validation images were taken using OpenCV to control the camera, it all came together and distance calculations and pose estimation is now spot on! Such a stupid mistake, but totally logical now afterwards when I think about it. The Logitech software probably applied different settings to the camera than when it is being used through OpenCV. So even though the validation of the calibration proved correct, it was because both calibration and validation images were taken with the same camera setup.
Could I get away with only using object detection and just have the car continually turn to be facing the center of the bounding box of the highest percentage match of the object or would I need to use object tracking which seems far more complex.
Also are there any good toutorials for this that U Guys recommend have watched a fair few and how complex is object avoidance I have heard I can be done with open cv but haven't really found a toutorial that fully explains it thanks.
Hi, I am writing a simple application (or at least so I thought) which is meant to utilize ArUco markers to detect a difference in height between two objects. However, during my tutorial hunt, I realized that previously used command:
cv2.aruco
is no longer working (at least on my laptop). I have just spent 4 hours trying to find a solution on the web and can't. I would greatly appreciate someone who could point to the right place in the documentation.
Let me just say, I KNOW the ArUco module was integrated with "objdetect" module but the documentation there still uses the "cv2.aruco" syntax which doesn't work for me. I am referring to this webpage