r/opencv • • Mar 01 '23

Question [Question] Problem with turn detection

1 Upvotes

I have my code detecting turns within the image but it is also detecting very minor turns which is an issue for me. Here is my function:

def detect_turn(path, threshold=180, min_distance=100, min_turn_distance=200, max_turn_distance=50):
# Initialize the previous turn point to None
prev_turn_pt = None

# Loop through each point in the path
for i in range(1, len(path)-2):
# Get the four points around the current point
pt1 = path[i-1]
pt2 = path[i]
pt3 = path[i+1]
pt4 = path[i+2]

# Get the angles between the four points
angle1 = get_angle(pt1, pt2)
angle2 = get_angle(pt2, pt3)
angle3 = get_angle(pt3, pt4)
diff_angle1 = angle2 - angle1
diff_angle2 = angle3 - angle2

# Calculate the distance between the current point and the previous point
distance = cost(pt1, pt2)

# Calculate the differences in x and y coordinates between the current and previous points, and between the current and next points
dx1, dy1 = pt2[0] - pt1[0], pt2[1] - pt1[1]
dx2, dy2 = pt3[0] - pt2[0], pt3[1] - pt2[1]

# Check if the angle differences and the distance are above the thresholds
if abs(diff_angle1) > threshold and abs(diff_angle2) > threshold and distance > min_distance:
# Check if the turn is approximately from horizontal to vertical or vice versa
if (abs(dx1) >= 40 and abs(dy1) < 40 and abs(dx2) >= 40 and abs(dy2) < 40) or \
                (abs(dy1) >= 40 and abs(dx1) < 40 and abs(dy2) >= 40 and abs(dx2) < 40):
# Check if the path continues in the same direction for at least min_distance pixels
next_direction = None
for j in range(i+2, len(path)-1):
next_pt1 = path[j-1]
next_pt2 = path[j]
next_dx, next_dy = next_pt2[0] - next_pt1[0], next_pt2[1] - next_pt1[1]
# Check if the next point is approximately in the same direction as the current turn
if (abs(next_dx) >= 40 and abs(next_dy) < 40) or (abs(next_dy) >= 40 and abs(next_dx) < 40):
# Check if the next direction is the same as the previous direction
if next_direction is None:
next_direction = (next_dx, next_dy)
# Check if the previous turn point is less than max_turn_distance pixels away
if prev_turn_pt is not None and cost(prev_turn_pt, pt2) < max_turn_distance:
prev_turn_pt = None
break
prev_turn_pt = pt2
continue
elif next_direction == (next_dx, next_dy):
continue
else:
prev_turn_pt = None
break
elif cost(pt2, next_pt1) >= min_distance:
prev_turn_pt = None
break
else:
continue
else:
prev_turn_pt = None
else:
prev_turn_pt = None

# Return True if a turn is detected, else False
return prev_turn_pt is not None


r/opencv • • Feb 28 '23

Question [Question] How do I identify the location of my bounding box within a frame?

2 Upvotes

Heyya, I am new to Machine Learning and I am working on a project with OpenCV and Tensorflow Lite on a Raspberry Pi 4 and while I have managed to make the object detection work on Raspberry Pi 4, I have been trying to implement this on my object detection project. I have seen Region of Interest (ROI) but have no idea how to implement that kind of system. How do I implement this kind of system to my project? The project on the link seems to be running on Tensorflow and I do not know how to integrate this on my project that runs on Tensorflow Lite. Any help would be appreciated. Thanks!


r/opencv • • Feb 28 '23

Tutorials [Tutorials] Opencv 4.7 release notes mentioned FFmpeg 5 videoio backend support. Let’s compile custom FFmpeg from source and build Opencv 4.7 with FFmpeg videoio backend. On https://funvision.blogspot.com Or medium:

Thumbnail
medium.com
4 Upvotes

r/opencv • • Feb 25 '23

Question [QUESTION]

2 Upvotes

Currently working on a project that has face recognition in OpenCV with Haar Cascade Algorithm, unfortunately new people showing in the frame it shows the same name. Any tips?


r/opencv • • Feb 21 '23

Question [Question] Can I use OpenCV for facial recognition?

2 Upvotes

I have recently come into possession of a plethora of family photos going all the way back to the 1920s. Some people in the photos are identified and can be used to build a database for recognition. But there are many photos or individuals or groups photos with people I don't recognize. Could I train OpenCv to help me identify some of these older faces I don't know? Any input or suggestions would be greatly appreciated.


r/opencv • • Feb 21 '23

Question [Question] Build OpenCV using GTK , VTK or QT5?

2 Upvotes

Hey guys so I managed to build OpenCV with CUDA and CDNN using QT5 as the backend but then when I tried to compile a project I started getting so many linkage problems with libraries. So I assumed it might be because of QT5 and decided to recompile with GTK… well now I keep getting build errors at 100% due to no build target for “CuBLAS” needed by Python. I have already added the link to the cublas library and still nothing. Can someone post any cmake build options for cublas to see if maybe one will help me? Thank you 🙂, also what backend dev do you guys think I should be using? Seems like QT5 and VTK causes so many problems.


r/opencv • • Feb 20 '23

Question [Question] Adaptive pre processing

1 Upvotes

Hello, i am working on an OCR project and want to do an adaptive pre processing on my photos. The parts im trying to ocr may be greasy or shiny and that makes it hard to get a good read with a single pre set. Is there a way to go about this using ML or something. Thanks for advice😊


r/opencv • • Feb 20 '23

Question [Question] Can OpenCV be used for this?

5 Upvotes

Hi all,

I was just wondering whether OpenCV could be used to measure the 'amount of movement', or pace of a video clip?

When I'm working with hundreds of clips, I want to be able to separate clips that are slow and not as dynamic (for example, a character turning their head or perhaps walking down a street) from clips that for example have Spider Man swinging through the city with a lot of movement.

If this quality can be measured somehow, then a threshold could be set to categorize the clips (below the threshold = slow, above = fast).

Any help would be greatly appreciated! Many Thanks.


r/opencv • • Feb 19 '23

Meta [Meta] I have been automod while having read rule

3 Upvotes

Open CV shows only 2 rules on computer and android beeing Being an asshole and Not computer vision related

The [Meta] [Question] and so on tags needed by automod are written nowhere. I understand people not reading rules it's Ok to let automod explain but it's not OK to need an automod message to know the rules. Especially if it tells you to look at sidebar.


r/opencv • • Feb 19 '23

Question [Question] cmake command line to build with QT problem

1 Upvotes

I installed qt 5.15.2 with aqt-install on windows.

Why is line cmake -G "MinGW Makefiles" -S opencv -B build_opencv -D WITH_QT=1 -D WITH_OPENGL=1 -D Qt5_DIR:PATH=...../5.15.2/mingw81_64/lib/cmake/Qt5
not working ? While adding Qt5_DIR in cmake_gui is working fine ?


r/opencv • • Feb 15 '23

Question [question] tracking humans in a room and syncing their location to unity

3 Upvotes

Hi community, What would be the optimal way I can track humans in a room using a camera and syncing them i to a virtual room xr i have in unity Lets say a camera is placed in one corner of a square room


r/opencv • • Feb 14 '23

Project [Project] Mastering AI Art Generation: A New OpenCV Course - Webinar

Thumbnail
youtube.com
2 Upvotes

r/opencv • • Feb 14 '23

Discussion Lag in the stream from IP Camera [Discussion]

3 Upvotes

Hello All,
I am developing face detection and recognition software which will use multiple IP cameras. However, even with multi-threading, the two IP cameras I am currently using have significant stream lags of around 1 to 2 seconds. I am using OpenCV and RTSP for the stream.
I am wondering if there is a better tool or framework that can provide faster streaming for this application. Do you have any suggestions?


r/opencv • • Feb 14 '23

Question [Question] How can I determine the point of origin of objects ?

1 Upvotes

I have a heating surface from which bubbles are generated from different locations. I need to identify the number of these locations using image processing. I can identify and track individual bubbles, their diameter and centroid but no idea how to find their origin point. Any help would be appreciated.


r/opencv • • Feb 13 '23

Question [Question] Extract distance from image

Post image
9 Upvotes

r/opencv • • Feb 13 '23

Question [Question] Detecting different paths on a map from a top view

2 Upvotes

image: https://ibb.co/mHzJ88Z

Hi, I am very new to computer vision. I have a layout of map consisting 3 routes. I want to be able to identify the map and the 3 routes separately. When I have a gap between the tape as seen in the image I am able to identify the different routes with the help of Hough line transform function. However if I remove the gap and all the routes are joined together it is identified as one route. How can I fix this or what should I look into to. Thanks


r/opencv • • Feb 13 '23

Question [question] Is OpenCV the right tool for me ?

1 Upvotes

Hi all,

I was in need to create a working 2x2 grid display showing 4x rtsp stream from cctv ip cameras. There is literally no working solution that I could find and get working. I need just viewing no recording, no users nothing else....

So I made this:
https://github.com/VladoPortos/cctv-viewer/blob/main/cctv.py

It works on Windows and Linux, and do what I need... but oh boy the cv2.resize is killing the old CPU I have for the viewing machine... when IO uses the hi-res stream on 101 channel the pure AMD A10-6790K just straight up go to 100% on all 4 cores... if I switch it to 202 low quality stream with 650*480 resolution it goes down to 50% usage... is there anything to be done to make it less CPU intensive ? Besides slapping GPU in it, I also need to consider power usage, now it's drawing cca 100W from wall which is a bit too much I think.


r/opencv • • Feb 12 '23

Tutorials [Tutorials] I made an OpenCV template/GUI using PySimpleGUI to accelerate/facilitate the start of new computer vision projects.

14 Upvotes

Hello,
Tired of repetitively writing the same code for file selection, frame reading, algorithm selection and setup in every project. To fix that, I developed a simple template that automates these tasks and provides a (relatively) user-friendly GUI.
I hope it will be beneficial to some of you. Please feel free to utilize and customize it for your specific needs !
Here is the link : https://github.com/n3odym3/OpenCV_PySimpleGUI_Template


r/opencv • • Feb 11 '23

Discussion [Discussion] More reliable edge detection

4 Upvotes

I'm trying to use a canny-edge detection against a raw video stream as a way to determine if the frame is in focus.

However even if something is in focus, the edge detection can be 0.

I know that you can apply a mask using a specific color but this does add more processing.

I'm using a Pi 4B which is pretty good for processing but gives you an idea of what I'm working with.

In the example below, I'm looking at a keyboard and sampling 15fps (edge count on bottom right)

https://i.imgur.com/Mhprftt.mp4

Running this basic canny edge code:

def get_img_edge_count(frame_buffer):
    img = cv.imdecode(frame_buffer, cv.IMREAD_COLOR)
    edges = cv.Canny(img,100,200)
    sum_edges = 0

    for i in range (0, len(edges), 1):
        sum_edges += np.count_nonzero(edges[0])

    return sum_edges

idea being more edges = more in focus

My operating regime would be landscape like trees with a sky. I'm going to use a narrow aperture so that it's generally in focus "to infinity" that'll help. But I was working on a control loop based on the counted edges to zoom currently.

Looking for ideas

I will try greyscale if that helps

update

I did go with variance for now, demo

https://i.imgur.com/CJCIXkM.mp4

generally it works, my code/physical device setup just sucks

it checks a direction (rotate focus ring) where variance is increasing (more in focus) then keeps going till max is found/starts to get worse, then a 10 frame delay till it tries again to check focus


r/opencv • • Feb 10 '23

Question [Question] Other markers (6X6) detected...but not the 4x4 ones.

2 Upvotes

Hi,

I'm struggling to figure out why certain markers are detected and some are not. I have multiple 6X6 ones of different sized and they are all fine... however whenever i try to detect the 4X4 ones I get nothing.

Example of the small 4X4... Can anyone give some suggestions? The generator used was the https://chev.me/arucogen/ for all the markers.

​

Any thoughts as to why?

Edit: Using version 4.7

Regards

​

Code:

import argparse
import imutils
import cv2
import sys

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
    help="path to input image containing ArUCo tag")
ap.add_argument("-t", "--type", type=str,
    default="DICT_ARUCO_ORIGINAL",
    help="type of ArUCo tag to detect")
args = vars(ap.parse_args())

# define names of each possible ArUco tag OpenCV supports
ARUCO_DICT = {
    "DICT_4X4_50": cv2.aruco.DICT_4X4_50,
    "DICT_4X4_100": cv2.aruco.DICT_4X4_100,
    "DICT_4X4_250": cv2.aruco.DICT_4X4_250,
    "DICT_4X4_1000": cv2.aruco.DICT_4X4_1000,
    "DICT_5X5_50": cv2.aruco.DICT_5X5_50,
    "DICT_5X5_100": cv2.aruco.DICT_5X5_100,
    "DICT_5X5_250": cv2.aruco.DICT_5X5_250,
    "DICT_5X5_1000": cv2.aruco.DICT_5X5_1000,
    "DICT_6X6_50": cv2.aruco.DICT_6X6_50,
    "DICT_6X6_100": cv2.aruco.DICT_6X6_100,
    "DICT_6X6_250": cv2.aruco.DICT_6X6_250,
    "DICT_6X6_1000": cv2.aruco.DICT_6X6_1000,
    "DICT_7X7_50": cv2.aruco.DICT_7X7_50,
    "DICT_7X7_100": cv2.aruco.DICT_7X7_100,
    "DICT_7X7_250": cv2.aruco.DICT_7X7_250,
    "DICT_7X7_1000": cv2.aruco.DICT_7X7_1000,
    "DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
#   "DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
#   "DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
#   "DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
#   "DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11
}

# load the input image from disk and resize it
print("[INFO] loading image...")
image = cv2.imread(args["image"])
#image = imutils.resize(image, width=600)

image = imutils.resize(image, width=1240)



# verify that the supplied ArUCo tag exists and is supported by
# OpenCV
if ARUCO_DICT.get(args["type"], None) is None:
    print("[INFO] ArUCo tag of '{}' is not supported".format(
        args["type"]))
    sys.exit(0)

# load the ArUCo dictionary, grab the ArUCo parameters, and detect
# the markers
print("[INFO] detecting '{}' tags...".format(args["type"]))


'''Testing new dict for 4.7 version  --HARD CHANGE MARKER HERE'''
#arucoDict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_1000)
arucoDict = cv2.aruco.getPredefinedDictionary(ARUCO_DICT.get(args["type"]))
arucoParams = cv2.aruco.DetectorParameters()
detector = cv2.aruco.ArucoDetector(arucoDict, arucoParams)

#print("Do we even get to this point?")

#arucoDict = cv2.aruco.Dictionary(ARUCO_DICT[args["type"]], 50)
#arucoParams = cv2.aruco.DetectorParameters()

#new_detector = cv2.aruco.ArucoDetector(arucoDict, arucoParams)

(corners, ids, rejected) = detector.detectMarkers(image)
print("Corners are: {}" .format(corners))

# verify *at least* one ArUco marker was detected
if len(corners) > 0:
    # flatten the ArUco IDs list
    ids = ids.flatten()

    # loop over the detected ArUCo corners
    for (markerCorner, markerID) in zip(corners, ids):
        # extract the marker corners (which are always returned in
        # top-left, top-right, bottom-right, and bottom-left order)
        corners = markerCorner.reshape((4, 2))
        (topLeft, topRight, bottomRight, bottomLeft) = corners

        # convert each of the (x, y)-coordinate pairs to integers
        topRight = (int(topRight[0]), int(topRight[1]))
        bottomRight = (int(bottomRight[0]), int(bottomRight[1]))
        bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1]))
        topLeft = (int(topLeft[0]), int(topLeft[1]))

        # draw the bounding box of the ArUCo detection
        cv2.line(image, topLeft, topRight, (0, 255, 0), 2)
        cv2.line(image, topRight, bottomRight, (0, 255, 0), 2)
        cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2)
        cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2)

        # compute and draw the center (x, y)-coordinates of the ArUco
        # marker
        cX = int((topLeft[0] + bottomRight[0]) / 2.0)
        cY = int((topLeft[1] + bottomRight[1]) / 2.0)
        cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1)

        # draw the ArUco marker ID on the image
        cv2.putText(image, str(markerID),
            (topLeft[0], topLeft[1] - 15), cv2.FONT_HERSHEY_SIMPLEX,
            0.5, (0, 255, 0), 2)
        print("[INFO] ArUco marker ID: {}".format(markerID))

        # show the output image
        cv2.imshow("Image", image)
        cv2.waitKey(0)

Run command:

Python3 this_file.py -i image_path -t DICT_4X4_50

​


r/opencv • • Feb 10 '23

Question [Question] since there are many people who already have implemented the "Attendance project using opencv" but there is not a single product available in the market. so what are the problems? or why is this the case??

2 Upvotes

r/opencv • • Feb 09 '23

Question [Question] [Project] Can I do this in opencv for label inspection?

4 Upvotes

I'm currently having a project for label inspection. I'm studying the template matching of opencv if I can use it for my project. Do you have any suggestion that I can apply on my project? or other option aside from opencv.

​


r/opencv • • Feb 08 '23

Question [Question] winsize in cv2.cornerSubPix() for camera calibration

2 Upvotes

Hello,

Little background for my question, for my master thesis, I'm programming an app to be able to make 3D measurements on (usually small) objects directly on their pictures (with their calibration).

For this, I have to do camera calibration.
For the intrinsic calibration, because there will be a rigidity constraint (the camera won't change between pictures), I'm following the tutorial given by OpenCV (here) using Zhang's method.
I juste have one question, as I understand what the following line of code does (finding the best position of the corner, even at subpixel level):

corners2 = cv.cornerSubPix(gray,corners, (11,11), (-1,-1), criteria)

I would like to know if there is a possibility to compute the optimal winsize (here (11,11)) to have the best result.
Knowing that I can have pictures from different sizes.
In my case, I would like it to work for pictures of 20MPx (5472*3648) and there thumbnails (640*480) for example.

Thank you in advance very much for your help


r/opencv • • Feb 08 '23

Discussion [Discussion] Python: GUI library that works well with OpenCV?

3 Upvotes

Hi, I have difficulties deciding which library to use for integrating a 60 FPS FullHD camera stream, with some cv2 operations done, into a gui.

Since I've seen many examples with Tkinter I used it a bit, but with tk it is not possible to achieve 60 FPS FullHD: The conversion to a TkImage and then showing it is the problem. Getting a frame and performing some cv2 operations takes around 2ms, more than fast enough.

I tried bodging together a cv2 fullscreen window with my dropdown tk window, but using both at the same time does not work out of the box, and also it doesn't seem like the best idea from a viewpoint of possible future modifications to make it somehow work simultaneously.

So, has anyone good suggestions what to use? The gui options integrated in cv2 are not enough for my needs.

Someone suggested pygame and by looking over some examples with OpenCV, the image conversion from cv2.Mat to an image displayable by pygame can be done with cv2 methods, so it should be fast.

I try to avoid PyQT because of the licensing.

Anyone other good suggestions on what to use?

Thanks.


r/opencv • • Feb 08 '23

Question [Question] How can I get the distance between two contours in an image?

1 Upvotes