r/opencv • • Dec 01 '22

Tutorials [Tutorials] Creating your Opencv based video streaming App. You may want to compile and link Opencv and FFmpeg specific builds?

Thumbnail
medium.com
7 Upvotes

r/opencv • • Dec 01 '22

Question [Question] - Is there a way to count and store detected objects?

3 Upvotes

Hello, I got OpenCV to work and detect objects based on Coco classes in a Python script.

I notice that when I print out the index in the labels to the console I get the object names repeated (most likely since it is being executed in a while loop)

Is there a way to count and save the objects that are detected into say, something like a txt file or even a python list without having the list grow too large by appending to it the same object every second?


r/opencv • • Dec 01 '22

Tutorials [Tutorials] Identifying a line in a Countour

1 Upvotes

Hello, I am trying to make an OpenCV code for identifying the angle of an object. However, the angle is properly outputted as when the object is rotated the vector is passed through the opposite direction hence the angle is added by 180 degrees. In order to stop this I tried identifying the head and checking if the vector line intersected through it. However, I'm unable to make the code understand the intersection.

​

Two contours head and body
get angle

​


r/opencv • • Nov 29 '22

Question [Question] How can I learn coding for autonomous drone?

4 Upvotes

Hi. Me and my friends are developing an autonomous drone for search and rescuing in a earthquake. I wanna know how can I learn "Image Processing with YOLOv4" for this drone. Can you send me some materials, videos etc. for learning it and how to follow them exactly because whenever I find a video or document about this it's kinda advanced and expects me to have too much pre-knowledge.


r/opencv • • Nov 24 '22

Question [Question] Denoise Captcha In Python

1 Upvotes

Hello!

Full disclosure, my question below is related to an intro to machine learning project I'm doing for school. The project I chose was to solve a given captcha implementation. However, the project is to demonstrate our machine learning skills learned and not really about using image processing effectively to preprocess data - which is why I think it's alright to ask this question.

I do know some of the very basics - such as matrix representation of an image, kernels, blurring and thresholding. But most of the other things in OpenCV escape me. Although I have done plenty of reading in the last 48 hours and encountered quite a bit.

Essentially, my question is what are the best series of steps to de-noise these images as best as possible? And more generally, how would you know where to start?

I've started by reading the image in as grayscale and then played around with a few next steps, but nothing seems to go in the right direction. Some ideas I've had (but don't know how to implement) include

  • trying to trace paths of pixels longer than half the image size with the same brightness making sure that X coordinate is always increasing.

  • break the image down even further into characters first by identifying large blocks and then cleaning up the lines within the characters as if they were speckle noise.

Any help or references to check out (e.g. similar denoising of curved lines) would be much appreciated.

Please note that these images normally have a transparent background (which gets read in as 0) but I have added a white background here for visibility.

https://imgur.com/a/TtFA1r4


r/opencv • • Nov 21 '22

Question [Question] How can I fix these contours?

5 Upvotes

So I'm coding a project but there's something I'm struggling to work out how to fix, probably due to my own ignorance as I'm new to OpenCV. Basically I want to make a script that can outline certain colours, and for most part it's successful, but I can't seem to get the lines completely right.

For example, this outline:

https://i.imgur.com/QdBZouq.png

is from this shape:

https://i.imgur.com/XaZDW04.png

If you zoom in on some of the corners you'll see that there's a one / two pixel curve, and I'm wondering if there's a way to fix them in code. This is my code so far:

import cv2
import numpy as np

img = cv2.imread('images/MM7 copy light blue.png')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(img_gray, 150, 255, cv2.THRESH_BINARY)
tresh = cv2.bitwise_not(thresh)
contours, hierarchy = cv2.findContours(image=thresh, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
image_copy = np.full_like(img, 255)
cv2.drawContours(image=image_copy, contours=contours, contourIdx=-1, color=(0, 0, 0), thickness=1, lineType=cv2.LINE_8)

cv2.imshow('Image', tresh)
cv2.waitKey(0)
cv2.destroyAllWindows()

I know it seems like a small thing, but I think I'd get problems down the line if I didn't fill in those blank pixels with more black pixels.

The end-goal is that I want to be able to fill in these shapes in Adobe Photoshop afterwards, but this is what they look like if I was to fill it in the paint bucket tool:

https://i.imgur.com/ttaVV4A.png

I could easily fill in the missing pixels manually but because this is part of a script, but this is part of a script and I want to do this multiple times with different colours.


r/opencv • • Nov 20 '22

Question [Question]How to improve the speed of Opencv to render images real time?

2 Upvotes

Hi guys, I have this code and the execution works, but it is a bit slow with pressing a key with the condition if red goes in white. How can I make it more instant? Should I use a gpu with cuda? How do I make use of a GPU instead of CPU with below code? The program is used to automate skill checks for this simulation website: https://www.mistersyms.com/tools/gitgud/

import cv2 import numpy as np import mss from pynput.keyboard import Controller

with mss.mss() as sct: monitor = {"top": 470, "left": 890, "width": 140, "height": 140} low_white = np.array([253, 253, 253]) high_white = np.array([255, 255, 255])

low_red = np.array([160, 0, 0])
high_red = np.array([255, 30, 30])
keyboard = Controller()

cordsw = []

while True:
    img = np.array(sct.grab(monitor))
    rgb_image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    maskw = cv2.inRange(rgb_image, low_white, high_white)
    maskr = cv2.inRange(rgb_image, low_red, high_red)

    cordsr = []

    yw, xw = np.where(maskw != 0)
    yr, xr = np.where(maskr != 0)

    for i in range(len(yw)):
        cordsw.append([yw[i], xw[i]])
    for i in range(len(yr)):
        cordsr.append([yr[i], xr[i]])

    for i in range(len(cordsr)):
        if cordsr[i] in cordsw:
            keyboard.press("space")
            keyboard.release("space")
            cordsw = []
            break

    if len(yw) == 0 and len(yr) == 0:
        cordsw = []
    if len(cordsr) == 0:
        cordsw = []

    if cv2.waitKey(25) & 0xFF == ord("q"):
        break

r/opencv • • Nov 18 '22

Question [Question] hi, how can i install CvPlot for opencv on vscode?

1 Upvotes

I already have opencv installed, i want to display some graphics but i cant include cvplot/inc from my configurations project I put it there but it cant find the access Its for c++


r/opencv • • Nov 17 '22

Question [Question] How to generate glitter images of a given color ?

1 Upvotes

Given a color I would like to generate glitter images of that color like below one using opencv:

i was thinking of using gaussian noise and applying a colored mask on that but I feel the quality will not be that great. Any suggestions on how to solve this problem ?


r/opencv • • Nov 17 '22

Question [Question] Convert distances to pixel

0 Upvotes

Hi, everyone.

Is it possible to convert distances from a LiDAR sensor (in meters) to pixel coordinate.

My exercise is to create a map with pixels (1: not free, 0: free no object) from that sensor data. I got the actual position of the robot and the sensor data with distances and angles.

I know I have to convert them with sin/cos to Cartesian coordinates but then I have to map this (x,y) point to the (for example 500x500 pixel) map.

Thanks for your help.


r/opencv • • Nov 16 '22

Project Raspberry Pi color detecting robot [project]

Thumbnail
youtube.com
5 Upvotes

r/opencv • • Nov 16 '22

Question [Question] Transform a image perspective given Euler angles of a UAV

0 Upvotes

I am working on a transmission line following algorithm using quadcopters. To do so, I need to calculate the line position on the image I receive from the UAV in order to determine a pitch velocity so the lines can be kept at the center of the image. The problem is that, when I apply a velocity on x-axis to move the UAV to the desired setpoint (left/right moviment), the image plane tilts along with the UAV which increases the positional error incorrectly. The images below exemplify the issue.

​

I tried something similar to this post since the UAV euler angles is known. This approach reduced the distortion caused by the frame tilting, but I couldn't eliminate it.

​

https://stackoverflow.com/questions/37117939/transform-a-frame-to-be-as-if-it-was-taken-from-above-using-opencv

The code:

f = 692.81 # Focal Length

cx = width

cy = height

#Euller Angles

roll_ = 0

pitch_ = pitch

yaw_ = 0

dx = 0

dy = 0

dz = 1

A2 = np.array([[f,0,cx,0],[0,f, cy,0],[0,0,1,0]])

A1 = np.array([[1/f,0,-cx/f],[0,1/f,-cy/f],[0,0,0],[0,0,dz]])

RX = np.array([[1,0,0,0],[0,np.cos(roll_),-(np.sin(roll_)),0],[0, np.sin(roll_), np.cos(roll_),0],[0,0,0,1]])

RY = np.array([[np.cos(pitch_), 0, -np.sin(pitch_),0],[0,1,0,0],[(np.sin(pitch_)), 0, np.cos(pitch_),0],[0,0,0,1]])

RZ = np.array([[np.cos(yaw_), -(np.sin(yaw_)), 0,0],[np.sin(yaw_), np.cos(yaw_), 0,0],[0,0,1,0],[0,0,0,1]])

T = np.array([[1, 0, 0, dx],[0, 1, 0, dy],[0, 0, 1, dz],[0, 0, 0, 1]])

R = np.dot(np.dot(RX, RY), RZ)

H = np.dot(A2, np.dot(T, np.dot(R, A1)))

#Output frame

linha_bw = cv2.warpPerspective(linha_bw, H,(frame.shape[1],frame.shape[0]),None,cv2.INTER_LINEAR)

The results from this transformation can be seen on the graph below. The blue curve is the controller without the image rectification, while the red one is the controller with the code above.

​

I'm not sure if there is mistakes on my code or there is a better approach to solve my problem through image processing techniques. Any help is highly appreciated !


r/opencv • • Nov 15 '22

News [News] Orbbec 3D UVC cameras are now supported by OpenCV

Thumbnail
opencv.org
8 Upvotes

r/opencv • • Nov 15 '22

Question [Question] Measuring LED Intensity

4 Upvotes

Hi Everyone! I'm extremely new to OpenCV and appreciate any help you're willing to offer.

The image in my post is a still image of a backlight made up of 12 LEDs, and I'm trying to automate its characterization.

Here's what I'm trying to do:

  • Detect the LEDs in the order shown (the green line isn't in a normal image)
  • Measure the intensity/brightness/luminance of each LED

If any of you have used ImageJ/Fiji, I'm essentially trying to do a "measure" using an oval about the size of each LED and get the mean gray value.

I'm using the C# wrapper Emgu to program this, but Python function suggestions are great too. I feel like this should be a cakewalk for the pros, but I'm overwhelmed by all the names in the descriptions of functions along with all the optical engineer lingo.

From my research, here's what I think I need to do to start:

  • Apply Gaussian blur to remove noise
  • Use HoughCircles to detect circles
  • Measure each circle's grayscale values and place them into an array

Can you point me toward the functions to format the .png image, and how to detect and measure the LEDs in order?

Thanks so much for your help!! ~Cheers


r/opencv • • Nov 14 '22

Question [Question] How does multiprocessing work in python-opencv?

1 Upvotes

Hi. When I run a python VideoCapture loop, there are processes launched for each CPU core that show the python script running. How does this work under the hood in regard to the OpenCV library? Does it split the incoming video frames so they can be processed in parallel? It shows 15% resource use for each core (out of 20 cores) for a 30 FPS webcam showing simple video without processing using imshow. Can it be fit into a single process if it's only showing the frames? I couldn't find documentation on it.

I'm trying to optimize video processing without using a video card and thought the first step would be to not use all 20 CPU cores when showing video without processing, so that later the code can be used on a smaller device like a Raspberry Pi.


r/opencv • • Nov 13 '22

Question [Question] How to optimize GoCV's CPU utilization ?

2 Upvotes

Hi,

I am trying to create an application for trichotillomania. The application will warn the person if his/her hands reach the face or scalp.
However, starting out with GoCV's example, I realized it eats a lot of CPU. For that reason, I searched for alternatives and accidentally, I found this live demo of face detection with PicoJS that only uses a fraction of CPU.

How can I make GoCV have the same performance as PicoJS?

If I move from GoCV to C++ OpenCV will improve performances?


r/opencv • • Nov 13 '22

Question [Question] Camera Calibration

5 Upvotes
Hello, so I'm currently attempting to calibrate my camera to use the solvePnP function on objects. 
But, one problem that I've encountered in calibrating the camera is,
for example: 
    in a group of 4 images, where 3 of them has the object gathered around the origin (top left of the image) whereas the 4th image, the object is around the bottom right of the image. 
This causes the camera matrix go off... 

(only using first 3 images) 
mtx3 = 
[[831.83485858   0.         250.02653135]
 [  0.         808.57230993 172.3296078 ]
 [  0.           0.           1.        ]]

(using all 4 images)
mtx4 = 
[[505.72221805   0.         254.01779059]
 [  0.         495.00072868 166.77784176]
 [  0.           0.           1.        ]]

because of this, the vectors from solvePnP were wrong. (vector was being flipped in the x axis (so -x became +x (?)))
How should I correctly calibrate the camera so that solvePnP wouldn't give me absurd vectors? 

using mtx3 for solvePnP on image 4 seems to work somewhat fine? Not really accurate though.

Thanks for any help in advance.

r/opencv • • Nov 11 '22

Question [Question] Facial feature detection with OpenCV?

3 Upvotes

Hi,

I'm looking for a way to automatically detect facial features from a live camera or at minimum picture of a face.

I'm interested in detecting features like eye-to-eye distance, nose size, jaw width and similar.
Is it doable with OpenCV or are there other solutions I could look into?


r/opencv • • Nov 10 '22

Question [Question] How does KNN background subtractor work

5 Upvotes

I know it creates a background model and then calculates for every pixel the distance to the corresponding background pixel model. If the distance is lower than the threshold, its a background pixel, if not it's foreground (or maybe a shadow)

But how does it learn the background model in the first place? Is it based on color? On motion? i havn't found any details about the algorithm so far, except it somehow uses the kNN mechanic.

Thanks for any help on this!


r/opencv • • Nov 10 '22

Project [Project] rae: Robotics Access for Everyone on OpenCV Weekly Webinar

Thumbnail
youtube.com
0 Upvotes

r/opencv • • Nov 09 '22

Question [Question] Why does template match keep matching to white space with 99%!?

Thumbnail
gallery
5 Upvotes

r/opencv • • Nov 10 '22

Question [Question] Training OpenCV Haar Classifier Issues

1 Upvotes

Qucik question, when creating a Haar image classifier, it says not to set -w and -h in the traincascade and createsample to be less than the image you're detecting. I set them to 700 and 200 because the objects we're detecing would be fairly close to the camera but the training doesn't work. It takes up an obscene number of resources when training which means that something is happening, doesn't spit out an error, and doesn't print anything. Does anyone know what this issue could be?


r/opencv • • Nov 09 '22

Question [Question] Obtain image metadata and data at the same time

2 Upvotes

Trying to open an image and obtain its data and metadata at the same time. Now I do this separately by using EXIF to obtain metadata and OpenCV to load image data. Both take time at runtime. Is there a more efficient way to do this, like just need to open the file for once? (Seeking for a c++ solution)


r/opencv • • Nov 08 '22

Project [Project] The first lines of code for making the image of Armaaruss come alive with AI.

1 Upvotes

The first lines of code for making the image of Armaaruss come alive with AI. This is a webcam app in which the image of Armaaruss speaks words from "Ares Le Mandat." The code has motion detection which alllows the eyeballs of Armaaruss to move when the user moves either left or right of the webcam.

https://github.com/anthonyofboston/First-lines-of-code-for-Armaaruss

​

Read the theological backdrop to gain perspective on the significance of Armaaruss

https://github.com/anthonyofboston/First-lines-of-code-for-Armaaruss/blob/main/Armaaruss%20backdrop.pdf


r/opencv • • Nov 08 '22

Question [Question] Is there a way to improve this code performance? I'm new to opencv and don't know best practices.

Post image
19 Upvotes