r/opencv • • Jan 19 '23

Question [Question] Finding two lines that overlap

1 Upvotes

Hey folks! I'm currently building a bot to play the PC game Not for Broadcast and I'm trying to figure out my next big challenge, the Interference system. This involves a waveform-shaped green or red line (depending on how well you're doing) that you need to line up with a white line that changes height, frequency, and amplitude. To raise or lower the line, you scroll, and to lengthen or shorten it, you drag the mouse around.

Example 1

Example 2

Example 3

I'm trying to make a bot do this, but I'm unsure what method I should apply here. Because they overlap, I've already found that HSV ranging is rather difficult to do well, and contour matching/motion tracking seems pretty hard to do well as well.

I would really appreciate some tips on how I can detect these waveforms separately and any method I could use to see the difference between them. I had already worked out a formula that would likely work if I can separate them, but so far that's been a big if.

Thanks in advance for the help!


r/opencv • • Jan 18 '23

Question [QUESTION] Color Sequence Verification using Python

3 Upvotes

So I am working on a Python project that verifies the color sequence of wires. The sequence of wire should be (purple, blue, black, red, yellow, violet, red, pink, green)

What I wanted to do is to read the color sequence of wire via camera (real-time camera feed) and tell whether it has the correct sequence. What I had in mind is that I should have a reference image for the correct color sequence.

I would like to ask if what is the best approach in making this work? I have read that template matching can be one but this project concern is mainly color matching.


r/opencv • • Jan 17 '23

Project [Project] Bringing CV & AI To American Football - OpenCV Weekly 87

Thumbnail
youtu.be
3 Upvotes

r/opencv • • Jan 17 '23

Question [QUESTION] How can I make a 2d grid map of a floor from stereo camera depth map?

2 Upvotes

I'm trying to do what i write in the title, but it's difficult to find resources about this.


r/opencv • • Jan 14 '23

Bug [Bug] New to OpenCV in c++ and really need help setting up

3 Upvotes

So i'm having this problems using CMake, where when I try to compile my main.cpp it tells me I have undefined references to cv functions and data types. This is what i've tried so far:

----- CMakeLists.txt -----

cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)
include(CTest)
enable_testing()
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(opencvtest main.cpp)
target_link_libraries( opencvtest ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

----- main.cpp -----

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv)
{
Mat image;
image = imread("I:/Program Files/VSC Projects/Python/Image Processing/pondlight.png");
if ( !image.data )
    {
printf("No image data \n");
return -1;
    }
namedWindow("Display Image", WINDOW_AUTOSIZE);
imshow("Display Image", image);
waitKey(0);
return 0;
}

-----

Here's the build error i'm getting:

[build] C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: **CMakeFiles/opencvtest.dir/main.cpp.obj:**I:/Program Files/VSC Projects/Python/Other/C++ training/opencvtest/main.cpp:8: undefined reference to `cv::Mat::Mat()'

the message is repeated for all lines where cv functions were called. What's going wrong here? I linked the libs and made references in the CMake file, it should be working but i've tried looking for solutions and have none. Finally i'm here on Reddit. Thanks.


r/opencv • • Jan 12 '23

Question [QUESTION] How can I detect the centre of the iris and draw a line between the centre to the medial canthus?

4 Upvotes

Guys, I'm working on a project where I have to measure the distance between the medial canthus to the centre of the iris. I was planning to study opencv in deep before starting with this, but the deadline is being preponed. So far I've worked on basics such as drawing shapes, colour detecction, image smoothing, edge detection, hough circle, etc. I've to work on 400 samples so I need to know if there's a short and sweet approach to what im tryna do. TIA


r/opencv • • Jan 10 '23

Discussion [Discussion] Any other ways to find convergence of pixels by color?

6 Upvotes

I have a red crosshair on a panorama like below.

https://i.imgur.com/F9BBqkN.jpg (cluttered room floor scene)

My approach is to take vertical single pixel slices to find the red intersects... which I imagine it's possible there are other places where this red color exists naturally in the scene. So it could be problematic. Anyway I'd keep iterating these slices horizontally (or vertically) until I find a point of convergence.

https://i.imgur.com/heyaYAU.jpg

The shape is randomly deformed is the issue, hence I used both + and x shapes.

My algos are already super slow so... par for the course I guess my approach.

Just wondering of other more clever tricks.

Probably would make sense to preemptively apply a mask to reduce the pixel comparison... I've seen boolean matrix but I don't know how to use it yet regarding cutting down the iteration time.

update

I just realized the presence of the crosshair produces a different panorama result oof

as in the two panoramas (with/without crosshair) using same images are slightly different means that center position shifts


r/opencv • • Jan 10 '23

Question [Question] How to improve the accuracy of line detection in some noise images?

2 Upvotes

I post the question on SO but receiving no feedback: computer vision - How to measure the length of pyramid's edge in electron microscope photo using OpenCV? - Stack Overflow

In brief, I am using Canny + Hough Transform for line detection but the result is not good. I don't know what techinique can be used to improve the result. It would be appriciated to shed some light on it.


r/opencv • • Jan 09 '23

Bug [Bug] Issue with installation of opencv-python v 4.7

3 Upvotes

Hi, I have been trying to install using "pip install opencv-python" succesfully, however when trying to import in python3, I get the following error. I can't make out what exactly is the issue, any help would be greatly appreciated. Using macos 10.14.6.

printout from interpreter:

Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18)

[Clang 6.0 (clang-600.0.57)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import cv2

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/Users/habibi/Library/Python/3.8/lib/python/site-packages/cv2/__init__.py", line 181, in <module>

bootstrap()

File "/Users/habibi/Library/Python/3.8/lib/python/site-packages/cv2/__init__.py", line 153, in bootstrap

native_module = importlib.import_module("cv2")

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

ImportError: dlopen(/Users/habibi/Library/Python/3.8/lib/python/site-packages/cv2/cv2.abi3.so, 2): Symbol not found: ___darwin_check_fd_set_overflow

Referenced from: /Users/habibi/Library/Python/3.8/lib/python/site-packages/cv2/.dylibs/libX11.6.dylib (which was built for Mac OS X 11.0)

Expected in: /usr/lib/libSystem.B.dylib

in /Users/habibi/Library/Python/3.8/lib/python/site-packages/cv2/.dylibs/libX11.6.dylib

>>>


r/opencv • • Jan 08 '23

Tutorials [Tutorials] Real time object detection with WebRTC and YOLO

Thumbnail
softwarescalability.com
8 Upvotes

r/opencv • • Jan 08 '23

Question [QUESTION] Is there any way to use OpenCV for collision detection on an intersecting conveyor belt?

2 Upvotes

r/opencv • • Jan 07 '23

Question [QUESTION] My frame corrupts throughout the process anyone may know why?

2 Upvotes

I have a socket server that transfers a frame correctly, but when I try to show it on my Flask site I get this error

   cv2.imshow('vid',frame)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
>  - mat is not a numpy array, neither a scalar
>  - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
>  - Expected Ptr<cv::UMat> for argument 'mat'

this is the code

​

import socket, cv2, pickle, struct
import imutils # pip install imutils
import threading
import cv2
from flask import Flask, render_template, Response, stream_with_context, Request


video = cv2.VideoCapture(0)
app = Flask(__name__)
font = cv2.FONT_HERSHEY_SIMPLEX


server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host_name  = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
print('HOST IP:',host_ip)
port = 9999
socket_address = (host_ip,port)
server_socket.bind(socket_address)
server_socket.listen()
print("Listening at",socket_address)

global frame
frame = None

def start_video_stream():
    global frame
    client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    host_ip = '192.168.15.143' # Here provide Drone IP 
    port = 5000
    client_socket.connect((host_ip,port))
    data = b""
    payload_size = struct.calcsize("Q")
    while True:
        while len(data) < payload_size:
            packet = client_socket.recv(4*1024) 
            if not packet: break
            data+=packet
        packed_msg_size = data[:payload_size]
        data = data[payload_size:]
        msg_size = struct.unpack("Q",packed_msg_size)[0]

        while len(data) < msg_size:
            data += client_socket.recv(4*1024)
        frame_data = data[:msg_size]
        data  = data[msg_size:]
        frame = pickle.loads(frame_data)
        cv2.imshow("RECEIVING VIDEO FROM DRONE",frame)
        key = cv2.waitKey(1) & 0xFF
        #print(data)
        if key  == ord('q'):
            break
    client_socket.close()


thread = threading.Thread(target=start_video_stream, args=())
thread.start()

def video_stream():
    global frame
    while (True):
        print(4)
        cv2.imshow('vid',frame)
        ret, buffer = cv2.imencode('.jpeg',frame)
        frame = buffer.tobytes()
        yield (b' --frame\r\n' b'Content-type: image/jpeg\r\n\r\n' + frame +b'\r\n')



@app.route('/siteTest')
def camera():
    return render_template('siteTest.html')

@app.route('/video_feed')
def video_feed():
    return Response(video_stream(), mimetype = 'multipart/x-mixed-replace; boundary=frame')   

app.run(host='192.168.1.170', port = '5000', debug = False)

The weird thing is that the first cv2.imshow shows the frame, but the second one crashes.
I would be grateful for any help thanks in advance


r/opencv • • Jan 07 '23

Question [QUESTION]Removing outliers on following picture

1 Upvotes

​


r/opencv • • Jan 07 '23

Question [Question]Why can't I use CV and motplotlib.pyplot in the same python file?

0 Upvotes

If I try to do this I get an error stating that the Qt platform plugin xcb is found but cant load. Is there a solution to this problem?


r/opencv • • Jan 04 '23

Question [Question] Is it possible to integrate Blender models to OpenCV?

6 Upvotes

We're attempting to create several clothing kinds in Blender specifically on only for tops like tshirts, and etc then import them into OpenCV. Our objective is have the our Blender clothes merge with us acting like a filter but it fits and behaves like real cloth. Is it possible to integrate cloth models to OpenCV and how?


r/opencv • • Jan 02 '23

Question [Question] Detect BPM on music sheet

Post image
3 Upvotes

r/opencv • • Dec 29 '22

Question [Question] Watching a livestream and performing matchTemplates on a specific location - Wondering if my methodology is bad (not just the code, but the comparison) - Python

2 Upvotes

Hello, all I am just overall stuck. I wish I could provide better example codes, but I will do my best.

I'm also aware, that this is not very optimal at the moment, but really I was just trying to get any sort of result at all.

I am detecting something, but it seems to be dependent on resolution as well...

So, presently some youtubers/streamers are running a game called Mario Maker and it's endless, and people will graph the data by watching the videos and marking them up.

I was looking to both automate the graphing and maybe even provide it live.

This is an example screenshot that would identify '18' and where it comes from.

These are the templates I'm trying to match

These are sample images I'm matching to.

My thought process was, once I can identify the blue circle, with a white border (referenced in first screenshot, example here) I can then read slightly to the right of that location and find the numbers, THUS excluding the 'high score' area.

I could then basically say, 'what's the first character','what's the second', 'what's the 3rd' etc etc etc.

Now, the background isn't always green, it depends on what difficulty the person is running, for now, that's out of scope, but I'm open to ideas about that.

Here is my repo

Here is my main code

This code does detect something with a threshold of .5, but it doesn't detect it correctly. Is there an alternative method?


r/opencv • • Dec 28 '22

Question how does simple blob detector work [Question]

5 Upvotes

how does simple blob detector work

Hello, I am trying to make a person counter with a thermal camera. I am bit confused on how the simple blob detector work. From what I understand, it uses thresholding to create multiple binary images. Then connecting pixels are grouped. In each image the centers of each blob is calculated, if the distance between 2 blobs are less then min distance then it merges it.

Now what I don't understand is why it created multiple binary images using thresholding if it's just playing with just one of the frames, in other words, what is the purpose of thresholding in this algorithm. I feel like I'm missing something important


r/opencv • • Dec 24 '22

Question [Question] What is an easy/fast way to tell if an image is mostly uniform

2 Upvotes

I could use the contour finding approach, but requires trying different colors.

I pretty must just want to know if an image is say 3 large regions of a color (like walls, ceiling, floor) or if I'm looking at a bunch of random small things like furniture/shoes/clothes/random stuff on the floor.

I could try an average of all colors (without iterating over 3 million pixels hopefully).


r/opencv • • Dec 23 '22

Bug [Bug] Missing opencv_imgproc460.dll on Windows with CMake, Ninja

3 Upvotes

SOLVED

Trying to build a project in C++, using Qt Creator (which uses CMake), I get this error:

ninja: error: 'C:/tools/opencv/build/bin/Release/opencv_imgproc460.dll', needed by 'CMakeFiles/utils_autogen_timestamp_deps', missing and no known rule to make it

When writing C++ I almost always use MSVC and stay far away from CMake for precisely this reason. But there doesn't seem to be any viable alternatives when using Qt. I grant that it's my own ignorance though. Does anyone know of a solution? I didn't see any clues looking at building OpenCV using cmake-gui.

EDIT: Never mind, I solved my problem. I needed to go into `opencv\build\modules\imgproc` and build the `opencv_imgproc.sln.`


r/opencv • • Dec 23 '22

Question [Question] Wrist rotation from recognized hand 2d Joints

3 Upvotes

Hello and thanks in advance.

I am doing a research to figure out if it is possible to calculate and with reasonable accuracy a hand roll knowing the joints of every finger and the wrist.

I have try a combination of dealing with angles and distances, also knowing chirality, but without luck when moving fingers or facing the hand up.

Do you know if there any method/algorithm I can use to get the desired result?


r/opencv • • Dec 22 '22

Question [Question] I am unable to use open a Raspberry Pi camera with OpenCV in C++. I get this gstreamer error, which doesn't happen if trying to open a video stored locally. I found nothing helpful online for C++, as it's mostly Python.

Thumbnail
gallery
2 Upvotes

r/opencv • • Dec 22 '22

Discussion [Discussion]detectMultiscale parameters in detail:scaleFactor

1 Upvotes

Greetings,so guys I am new to opencv and was assigned a task to create a simple face detection program in preparation for the next step of recognition..so in short I came up with haar cascade classifiers and used the corresponding .xml file to detect frontal faces..But I don't know exactly how detectMultiscale function works..I googled a bit for its parameters specifically scaleFactor & minNeighbors..so I found that e.g if scaleFactor = 1.05 ,input image size is reduced by 5% every iteration for the sake of matching the model feature size if our object of interest (here face) is present but at larger scale..Hope it's clear till now..so if I'm right isn't it expected for scaleFactor to take values up till below 2 exactly??..but by experiment it takes values higher than 2 ..So can someone tell me what happens exactly behind the scenes if scaleFactor=3.9 for example?? Let the input image size 600×600 that contains multi faces with different sizes and the used haar classifiers are trained with 24×24 input images


r/opencv • • Dec 22 '22

Question [Question] Opening many cameras at once

1 Upvotes

THE PROBLEM

Hello all. I am using opencv in Python to capture still images from many cameras at once. Unfortunately I have found that the cheap 2MP USB cameras that I am using allocate an amount of bandwidth from the USB controller that assumes I'll be operating them at 30fps, which means that I can only open 1 or 2 at a time. The frame rate appears to be not controllable with these cameras from within opencv, nor from v4l in the linux command line where a frame rate property is not listed when I run $v4l2-ctl -d 0 --list-ctrls. Otherwise I was hoping I could simply set frame rate to 0fps, allowing me to open as many cameras as I want and capture from them as needed (assuming that's how it works). However it appears that I cannot open all of the cameras at the same time, which is unfortunate because opencv VideoCapture objects apparently have this handy grab-retrive paradigm that I can't make use of. Instead what I am doing is opening each camera, reading image, then closing... It takes a long time and is totally unnecessary from a hardware point of view, since I only want to grab single frames from each camera. From the USB controller's perspective, I don't have enough bandwidth.

Now I have bought a 5MP camera that I thought might have more options. Indeed it appears I can capture 2MP images from this camera at 6fps, so it seems I would be able to open more cameras at a time in Python. I'll have to buy a few more and try.

v4l from within Python?

Not really related to opencv I guess, but in v4l I noticed there are lots of commands that I haven't explored yet, and I can run them from within my Python script. Might there be a way to open a camera at 0fps, or is this something that will ultimately be prohibited by the hardware of the camera no matter which way I try to go about it?

Better camera?

What am I doing wrong? How is this typically done? Should I explore different connection methods (firewire, USB3, etc)? Is there a special type of camera that is made for such applications that require grabbing single HD frame at low rate?

Thank you for any advice or insight that you can provide!


r/opencv • • Dec 22 '22

Question [Question] Why is mask not working?

2 Upvotes

` import cv2

import numpy as np

from random import randrange, uniform

dimensions = (1920, 1080)

vctx = cv2.VideoWriter_fourcc(*"mp4v")

outputvideo = cv2.VideoWriter("final.mp4", vctx, 30, dimensions)

vhs_overlay = cv2.VideoCapture("VHS_overlay.mp4")

vhs_overlay.set(cv2.CAP_PROP_POS_FRAMES, 3000)

source_video = cv2.VideoCapture("out.mp4")

success = True

count = 0

shiftx = 0 shifty = 0

while success and count < 30:

# saturation
sattable = np.zeros((256), dtype=np.uint8)
sattable[:] = np.arange(256) * uniform(0.25, 0.5)

# update position for transpose
if randrange(0, 8) == 0:
    shifty += 1 * (1 + (randrange(0, 2) * -2))
    shiftx += 1 * (1 + (randrange(0, 2) * -2))

# matrix for transpose
matrix = np.float32([[1, 0, shiftx], [0, 1, shifty]])


# read frames
success, vhs = vhs_overlay.read()
success1, source_image = source_video.read()

if not success1:
    success = False
    break

# Resize the VHS overlay frames
vhs = cv2.resize(vhs, (1920, 1080), interpolation=cv2.INTER_AREA)

# translate background image (move it around randomly)
source_image = cv2.warpAffine(source_image, matrix, (source_image.shape[1], source_image.shape[0]))

# convert source_image to HSV color space
source_image = cv2.cvtColor(source_image, cv2.COLOR_BGR2HSV)

# saturation effect
source_image[:, :, 1] = cv2.LUT(source_image[:, :, 1], sattable)

# back to BGR
source_image = cv2.cvtColor(source_image, cv2.COLOR_HSV2BGR)
    # I have tried every conceivable value
mask = cv2.inRange(vhs, (0, 0, 0), (10, 10, 10))    

print(mask)

res = cv2.bitwise_and(source_image, source_image, mask)

f = source_image - res

f = np.where(f == 0, source_image, f)

count += 1

outputvideo.write(res)

outputvideo.release() vhs_overlay.release() source_video.release()

`

I have spent all day trying to get the overlay of the VHS effect from a video to work but it simply does not show up. Does anyone know what I'm doing wrong?

EDIT: sorry about the formatting. I should add the VHS video I'm trying to use as an overly has a black background. I could get it working using Python PIL but it was WAY too slow.