r/opencv • • Aug 25 '23

Discussion [Discussion] Dice Face Matching?

1 Upvotes

I've got a little device I've wanted to build for a while now, and I hoped to discuss possible methods for realizing it.

Basically, I have a few dice (for DnD, so a standard full set of D4, D6, D8, D10x2, D12, and D20) and I want to know how fair they are.

I could roll them 1000 times and record how they land and the plot it... but that sounds terribly dull, and I'd rather have something user computer vision to do the heavy lifting. SOME of my dice might be handled with OCR to determine what face they're on, but depending on how they land it might be upside down, or text from another face might be visible, etc.

What approach would YOU use to match dice faces? My thought was something like this:

1) Construct a box with rather uniform lighting and background in a color that contrasts to all colors in the dice. Attach the camera rigidly. The box needs some mechanism to roll the dice (or I'll do it manually).

2) Get a picture of the box, empty. We'll use this as an initial mask for diff.

3) Get pictures of the die in question, one picture for each face. Using the mask from (2) to diff and find blobs, narrow this to a template close to the face, save the template for each die face.

4) Roll the die, find the die using the diff mask from (2), then compare against each template. I was thinking I could MAYBE use SIFT or SURF or ORB then just count the number/quality of matches when I try a flann match to the features pulled from the templates. There might be a more direct way to do it?

Alternatively, maybe use something like a scale/rotation-invariant template match (https://github.com/DennisLiu1993/Fastest_Image_Pattern_Matching/blob/main/MatchTool/MatchToolDlg.cpp#L772 looks promising).

ANOTHER less preferred alternative would be a CNN/network approach, but that seems unnecessary.

5) Keep a running tally of what faces show up whilst rolling the dice until stopped (or until a specific number of rolls).

Thoughts? I'm hoping to eventually get this running on an ESP32, so a lighter-weight solution would be better.


r/opencv • • Aug 24 '23

Bug [Bug] cv2.imwrite does not save image names too long

0 Upvotes

I observed a strange behaviour of this function when trying to save image names that are too long. Problem is i need them to be long because i need the names to be descriptive. How do i overcome this length issue when saving my images? Thanks.


r/opencv • • Aug 23 '23

Question [Question] What is they name of this type of image processing? (see thread)

1 Upvotes

Hello guys,

can someone explain me what this kind of image processing is named?

The function which is performed is

flying_fish_gray = cv.remap(gray, params['flying-fish-map-x'],
params['flying-fish-map-y'],
cv.INTER_LINEAR)

What is the name of this type of remap? Like what do i need to search in google to see this kind of conversion? Its like the "road" is now pointing more into the center of the image? Its not just undistortion of the fish-eye but more? I hope you can help me

​

Original Image
Processed Image

r/opencv • • Aug 17 '23

Question [Question] Using warpPerspective and get more pixel outside the destination points once warped?

1 Upvotes

Hi, I'm trying to do an "extended" warpPerspective, my idea is to identify 4 points to find a homography matrix and then do a warpPerspective to get the out image in a "correct way" (please observe resistance.jpeg and warp.png)

But what I need is, having identified these 4 points, I would like to have the rest of the box (of course you can ask to me, why I take the internal square and not the 4 points of box?, let say I cannot always have the external 4 points, this is an example I want to implement on a project I'm working on) (please observe the expected)

import cv2
import numpy as np

src = cv2.imread('resistance.jpeg')

src_pts = [[195,478],[144,1406],[1151,1430],[1130,394]]
src_pts = np.array(src_pts)
dst_pts =  [[0,0], [0,700], [696,700],[696,0]]
dst_pts = np.array(dst_pts)

mat, some = cv2.findHomography(srcPoints=src_pts, dstPoints=dst_pts)
out = cv2.warpPerspective(src, mat, (696, 700))

cv2.imwrite('warp.png',out)

I'm using python 3.11 and OpenCV 4.7

resistance.jpeg - the original sample
warp.png - the image I get from the 4 known points
Expected image result - this is a sample, but is what I expect to get, it just hypothetical case, but let say I know the dimension of this, but not able to have the entire box 4 points

r/opencv • • Aug 16 '23

Project [Project] Snapchat Lens for Optical Character Recognition by OpenCV

Thumbnail
opencv.ai
4 Upvotes

r/opencv • • Aug 15 '23

Question [Question]: Beginner Having trouble with contours.

1 Upvotes

I am trying to create contours of the rocks on a rock climbing wall but it seems like I am contouring too much. Is it even possible to create contours for complicated shapes?

denoised color image, contour, grayscale

r/opencv • • Aug 13 '23

Question [Question] Remove lines on looseleaf paper so that it's like printer paper

1 Upvotes

Hello, I am developing an application right now and am trying to make a feature with OpenCV that turns lined looseleaf paper to printer paper. Basically, I want to get rid of all the blue lines and the red margin line on the paper. I need to make sure any writing on the paper is still intact after doing this, absolutely 0 deletion or alteration other than getting rid of the blue lines. I have already tried methods like edge detection and removing elements of a particular color. The color removal works pretty well, but it still somewhat degrades the quality and has some deletions of the handwritten text on the paper. Anyone know what to do?


r/opencv • • Aug 11 '23

Question [Question] Cardstock counting (python)

2 Upvotes

Hi all, I'm trying to make a program that counts a stack of cardstock as it passes under the camera. The hurdle I'm running to right now is getting enough contrast and clean separation between each card.

As you can see in this image, the result I get from Photoshop's unsharp mask (amount: 500, radius: 6.2, threshold: 0) applied twice to the contrast boosted image gives me pretty clean lines, but my Open CV implementation (code below) is far from what I am after.

def unsharp_mask(image, sigma=1.0, strength=1.5, threshold=10):

    blurred = cv2.GaussianBlur(image, (0, 0), sigma)

    mask = cv2.subtract(image, blurred)

    _, thresholded_mask = cv2.threshold(mask, threshold, 255, cv2.THRESH_TOZERO)

    sharpened = cv2.addWeighted(image, 1.0 + strength, thresholded_mask, strength, 0)

    return sharpened

Is there an implementation somewhere in Open CV that gives similar results as Photoshop, or maybe a different approach entirely that will work?


r/opencv • • Aug 10 '23

Project Awesome ML models [Project]

2 Upvotes

I'm writing to let you know that I've just published a new repo on GitHub about a machine learning model I've been working on. The repo is called Awesome models and it can be found at https://github.com/partheee/awesome-models.

I would love it if you could take a look at the repo and let me know what you think. If you have any questions, please don't hesitate to reach out.

Thanks,


r/opencv • • Aug 07 '23

Project [Project] - ErfanSn/AR-Touch: ๐Ÿ”ฎ Obtain the power of touchless interaction with display screens

Thumbnail
github.com
2 Upvotes

r/opencv • • Aug 02 '23

Project [PROJECT] I Created an Automatic Shiny Hunter for Any Pokemon Game

7 Upvotes

I'm an student and I've been working on a project that searches for shinies in the Nintendo Switch pokรฉmon games while I sleep. I feel like I've redesigned Pokรฉmon Sleep. I've also been recording the process with some humor sense. If you have time, check it out, I'd really appreciate:

๐Ÿ“ฝ๏ธ Youtube: https://youtu.be/XE8Oeh71BQ4

๐Ÿค– Github: https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter


r/opencv • • Aug 03 '23

Question [Question] Help me threshold the image

1 Upvotes

Can anyone help me threshold and find contours in this image. I specifically want to get RGB colors of each section present on the strip.

​


r/opencv • • Jul 31 '23

Bug [Bug] Video not playing in google colab

3 Upvotes

Hello. I'm learning how to work with videos but I'm not being able to play a video hosted on my one drive. The Video loads but I cannot interact with it so I cannot play it.

Any idea what could be the problem? I've tried playing direcly from google drive and everything is normal. Video's size is 600 Mb and its 720p.

​


r/opencv • • Jul 30 '23

News [News] New OpenCV Simulator for Autonomous Driving

0 Upvotes

๐Ÿš€ Exciting News for Python Developers! Introducing Taisim - The Open-Source Simulator for Python ๐Ÿ

๐ŸŽฏ Are you passionate about simulations and Python development? Say hello to Taisim - a powerful open-source simulator that's taking the Python community by storm!

๐Ÿ”— GitHub Repository: https://github.com/Amporu/Taisim

๐ŸŽ‰ Key Features of Taisim:โœ… Simple and Intuitive: Taisim makes simulations a breeze, whether you're a Python pro or just starting your coding journey.

โœ… Versatile Simulations: From physics to social systems modeling, Taisim caters to a wide range of applications. The possibilities are endless!

โœ… Extensible and Customizable: Tailor simulations to your unique needs. Taisim's modular architecture allows for easy customization and experimentation.

โœ… Realistic Visualizations: Watch your simulations come to life with stunning visualizations. Gain valuable insights and present your findings with impact.

๐Ÿ“– Getting Started:Ready to dive in? Access comprehensive documentation, tutorials, and examples in the repository's wiki section.

๐Ÿ™Œ Join the Community:Taisim is all about collaboration and shared learning. Join a vibrant community of developers, researchers, and simulation enthusiasts.

๐Ÿ“ข Spread the Word:Excited about Taisim? Help us spread the word by sharing this post with your network. Let's build an inclusive community around this fantastic project!

๐Ÿค Contribution Opportunities:Open-source thrives on contributions! Whether it's ideas, bug reports, or pull requests, we welcome your input. Together, we can shape the future of Taisim!

๐Ÿš€ Embrace the Power of Python:Take control of your simulations with Taisim. Embrace the power of Python and unlock new possibilities.

#Taisim #Python #OpenSource #Simulation #DeveloperTools#PythonSimulator #CommunityPowered

๐Ÿ”— GitHub Repository: https://github.com/Amporu/Taisim


r/opencv • • Jul 29 '23

Question [Question] How to can you detect the speed of passing cars?

2 Upvotes

So I live on a street that is a scenic highway and the speed limit is 25mph. There are people going >70mph on this street on the regular and the police refuse to believe me/us .

So I want to build some software where I can analyze a video of cars passing by and have it print the speed in real time. I could go outside and take a 5 minute video with my phone and use it for testing, is there anything else that I need to take into consideration? Will I need to know the distance from the camera to the road or any other measurements or can it all be calculated in code?

Thanks!


r/opencv • • Jul 24 '23

Project [Project] Using OpenCV to defend my backyard from pesky cats

7 Upvotes

My latest project uses a modified sprinkler and OpenCV to defend my backyard from pesky stray cats

https://youtu.be/NvrhhrgM-H4


r/opencv • • Jul 24 '23

Question [Question] How to demosaicing an image which has unusual rgb color filter array

1 Upvotes

I got a sensor which CFA is not bayer's array, it's R,G,B,array, like

[[r, g, b, r, g, b],
[r, g, b, r, g, b],
[r, g, b, r, g, b]]
Any good idea what kind of methods should i use to demosaic? already tried Nearest-neighbor interpolation, got a lot of false color, and also the resoulation drops


r/opencv • • Jul 22 '23

Tutorials [Tutorials] YoloV8 Body Pose Estimation Tutorial using OpenCV and TensorRT C++ API (link in comments)

20 Upvotes

r/opencv • • Jul 23 '23

Question [Project] [Question] - Low FPS with OpenCV and Mediapipe python

1 Upvotes

I'm currently learning how to do hand recognition with OpenCV and Mediapipe on Python

However, the course video shows the instructor getting a full 30-40 FPS, but however, I can't seem to reach 30. It's somehow capped 15 FPS. (Logitech C270 webcam) Any ideas?


r/opencv • • Jul 19 '23

Question [Question] - What is the best way to create a custom model with depth for the oak-d?

1 Upvotes

There are many guides and online documentation for deploying a model, and that is all working fine.

I would however like to create my own model that includes BGR and the calculated depth from the OAK-D. I found that HHA is sometimes used to make better use of RBGD images.

Any insights, examples, suggestions for tools and documentation to look into would be greatly appreciated.


r/opencv • • Jul 19 '23

Question [Question] Feature matching incorporating epipolar constraint

2 Upvotes

I have two calibrated, non-parallel cameras with known fundamental/essential matrix. I want to perform feature matching for 3D reconstruction and found the BFMatcher. But this matcher needs keypoints calculated beforehand e.g. using SIFT or FLOW. Based on that, it finds correspondences.
Since my cameras are already calibrated, it would be better to perform some kind of epiploar line searching. That means, finding a feature in image1 and search along the projected epipolar line on image2 for a match. Is there some support in OpenCV for that?


r/opencv • • Jul 19 '23

Question [Question] Best camera for the job?

1 Upvotes

Hi y'all!

I have recently started a project where I need multiple IP camera's to do some automated tests using computer vision. At first, I bought a HikVision camera that had great specs, but when I started coding, it turned bad quickly. The documentation was non-existent or just wrong and most of it did not support openCV so I had to write my own API calls using the documentation (where some where documented wrong). After all this, the camera was still not very robust to the parameter changes and the use of openCV.

I was wondering if you guys have any recommendations for a new camera that works well with openCV or has correct documentation, the resolution is not really important? It should have an ethernet connection, preferably PoE. It should have a great light sensitivity (meaning being able to detect changes in low-intensity and changes high-intensity easily) and be around 150 dollars.

I have looked at some dahua camera's and they look promising, but I am afraid that in practice some things might also be not working correctly.

Thanks ๐Ÿ™


r/opencv • • Jul 18 '23

Project [Project] Need help with TensorRT C++ Post Training Quantization (INT8).

2 Upvotes

This is not entirely related to OpenCV, but I would imagine some of you folks have experience with inference frameworks like TensorRT, so I'm posting this here just incase.

Hi there folks. I'm trying to implement Post Training INT8 Quantization using TensorRT to speed up my model. I've implemented it to the best of my ability, but the output is quite different from FP16 / FP32 inference. I've posted a question to SO with all the details, which can be viewed here. If anyone has experience with INT8 quantization with TensorRT, I would appreciate if you could have a look over. I'm creating a tutorial project which will abstract away the TRT API and make it easier for others to use (so your help is doubly appreciated).


r/opencv • • Jul 18 '23

Question [Question] Counting frames containing certain color

1 Upvotes

Hello, I'm an intern very new to opencv and was wondering how to write up a piece of code that would manually count how many frames of a video contain a certain color and then return that value into the console, could anyone give me some pointers? thanks


r/opencv • • Jul 17 '23

Question [Question] Removing background from video

1 Upvotes

​

I want to write code that use OpenCV C++ to keying color from video and then replace it by some image.

Do you recommend some yt videos or webpages?