• Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
Friday, November 21, 2025
newsaiworld
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
Morning News
No Result
View All Result
Home Machine Learning

How I Solved LinkedIn Queens Recreation Utilizing Backtracking | by Shanmukha Ranganath | Sep, 2024

Admin by Admin
September 29, 2024
in Machine Learning
0
1phpi Bay2gzdhgbrm1nweq.jpeg
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter

READ ALSO

How Relevance Fashions Foreshadowed Transformers for NLP

How Deep Characteristic Embeddings and Euclidean Similarity Energy Automated Plant Leaf Recognition


OpenCV (quick forOpen Supply Laptop Imaginative and prescient) is a library for Laptop Imaginative and prescient, Machine Studying, and Picture Processing. It may be used to determine patterns in a picture, extract options, and carry out mathematical operations on it. Step one is to course of the puzzle screenshot utilizing OpenCV, lets have a fast refresher on fundamentals of OpenCV picture processing.

Set up the OpenCV python package deal

pip set up opencv-python

The best way to load a picture

cv.imreadreads a picture file and converts it to an OpenCV matrix. If the picture can’t be learn as a result of the file could also be lacking or in a format that OpenCV can’t perceive an empty matrix is returned. The OpenCV matrix may be transformed to a picture again utilizing cv.imshow operate.

import cv2 as cv
import numpy as np

# Studying a picture
authentic = cv.imread(")
cv.imshow("authentic", authentic)

How to attract a line, circle, rectangle, textual content on the identical picture

As soon as we detect the grid, we have to recreate it utilizing traces and place Qutilizing textual content. Let’s have a look at a brief snippet to attract a line, circle, rectangle, and textual content on the above learn matrix.


# Drawing a line
line = cv.line(authentic, (authentic.form[1]//2, authentic.form[0]//2), (0,0) , (0,255,0), thickness=2)
cv.imshow("line", line)

# Drawing different shapes
circle = cv.circle(line, (line.form[1]//2, line.form[0]//2), 50, (0,0,255), thickness=2)
rect = cv.rectangle(circle, (10,10), (circle.form[1]//2, circle.form[0]//2), (255,0,0), thickness=2)
textual content = cv.putText(rect, "Hello", (rect.form[1]//2, rect.form[0]//2), cv.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), thickness=2)

cv.imshow("all shapes", textual content)

The best way to detect contours

Contours are merely a form becoming a member of all factors of comparable shade and depth at a steady boundary. These are helpful when detecting shapes and object define evaluation. We are going to draw our puzzle grid by detecting the person cells.

# Its greatest to transform picture to grayscale
# and add a little bit of blur for higher contour detections
# since our picture is generally a grid we dont want blur

# by default OpenCV reads photos as BGR
# versus conventional RGB
grey = cv.cvtConvert(authentic, cv.COLOR_BGR2GRAY)
contours, _ = cv.findContours(grey, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)

By default, OpenCV reads photos as BGR, versus conventional RGB

Cropping a picture

For us to remove pointless areas from screenshots and scale back noise, as soon as we’ve detected our contours

# its primarily choosing the pixels we want from your entire picture
cropped = authentic[0:original.shape[1]//2, 0:authentic.form[0]//2]
cv.imshow("cropped", cropped)

First, we start by loading the picture into reminiscence and changing it into Grayscale. This helps in simplifying contour detection, a common step that’s at all times adopted because it reduces the picture complexity. Subsequent, we discover contours, type them, and choose the biggest one. Usually, the primary contour is the sure field of the unique picture, so we use the second largest contour to isolate the puzzle grid. Then, we crop the picture simply to get the grid and nothing else. We once more discover contours, since now the noise is decreased, it’s going to detect the grid higher. We decide the variety of cells inside the grid and iterate over every cell, take the typical shade, and assign a lot of every shade, which supplies us the 2D array of our puzzle

# Learn the enter picture and save the unique
authentic = cv.imread(file_name)
cv.imwrite("resolution/authentic.png", authentic)

# Convert the picture to grayscale
grey = cv.cvtColor(authentic, cv.COLOR_BGR2GRAY)

# Discover contours within the grayscale picture and type them by space
contours, _ = cv.findContours(grey, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
contours = sorted(contours, key=cv.contourArea, reverse=True)

# Extract the bounding field of the puzzle grid (utilizing the second largest contour)
x, y, w, h = cv.boundingRect(contours[1])

# Crop the grid space from the unique picture
grid = authentic[y:y+h, x:x+w]
cv.imwrite("resolution/grid.png", grid)

# Convert the cropped grid to grayscale
grey = cv.cvtColor(grid, cv.COLOR_BGR2GRAY)
cv.imwrite("resolution/gray-grid.png", grey)

# Discover contours once more within the cropped grayscale grid
contours, _ = cv.findContours(grey, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
contours = sorted(contours, key=cv.contourArea)

# Decide the whole variety of cells within the grid
total_cells = len(contours) - 2
grid_size = int(math.sqrt(total_cells))

# Examine if the detected cells type a whole sq. grid
if total_cells != grid_size**2:
print("Unable to detect full grid! Aborting")

# Calculate particular person cell dimensions
cell_width = w // grid_size
cell_height = h // grid_size

# Initialize shade mappings and board illustration
colours = []
board = []
color_index = 1
color_map = {}
reverse_color_map = {}
padding = 10

# Iterate by way of every cell within the grid
for i in vary(grid_size):
row = []
for j in vary(grid_size):
# Calculate cell coordinates with padding
cell_x = j * cell_width
cell_y = i * cell_height
padding = 15
cell = grid[cell_y+padding:cell_y+cell_height-padding, cell_x+padding:cell_x+cell_width-padding]

# Get the typical shade of the cell
avg_color = cell.imply(axis=0).imply(axis=0)
avg_color = avg_color.astype(int)
avg_color = tuple(avg_color)

# Map the colour to a singular index if not already mapped
if avg_color not in color_map:
color_map[avg_color] = str(color_index)
reverse_color_map[str(color_index)] = avg_color
color_index += 1

# Add the colour index to the row
row.append(color_map[avg_color])

# Add the row to the board
board.append(row)

Tags: BacktrackingGameLinkedinQueensRanganathSepShanmukhaSolved

Related Posts

Screenshot 2025 11 18 at 18.28.22 4.jpg
Machine Learning

How Relevance Fashions Foreshadowed Transformers for NLP

November 20, 2025
Image 155.png
Machine Learning

How Deep Characteristic Embeddings and Euclidean Similarity Energy Automated Plant Leaf Recognition

November 19, 2025
Stockcake vintage computer programming 1763145811.jpg
Machine Learning

Javascript Fatigue: HTMX Is All You Must Construct ChatGPT — Half 2

November 18, 2025
Gemini generated image 7tgk1y7tgk1y7tgk 1.jpg
Machine Learning

Cease Worrying about AGI: The Quick Hazard is Decreased Basic Intelligence (RGI)

November 17, 2025
Mlm chugani 10 python one liners calculating model feature importance feature 1024x683.png
Machine Learning

10 Python One-Liners for Calculating Mannequin Characteristic Significance

November 16, 2025
Evelina siuksteryte scaled 1.jpg
Machine Learning

Music, Lyrics, and Agentic AI: Constructing a Sensible Tune Explainer utilizing Python and OpenAI

November 15, 2025
Next Post
1ly0au9wo02v3hwtw5h9j2q.png

Mannequin Deployment with FastAPI, Azure, and Docker | by Sabrine Bendimerad | Sep, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

POPULAR NEWS

Gemini 2.0 Fash Vs Gpt 4o.webp.webp

Gemini 2.0 Flash vs GPT 4o: Which is Higher?

January 19, 2025
Blog.png

XMN is accessible for buying and selling!

October 10, 2025
0 3.png

College endowments be a part of crypto rush, boosting meme cash like Meme Index

February 10, 2025
Holdinghands.png

What My GPT Stylist Taught Me About Prompting Higher

May 10, 2025
1da3lz S3h Cujupuolbtvw.png

Scaling Statistics: Incremental Customary Deviation in SQL with dbt | by Yuval Gorchover | Jan, 2025

January 2, 2025

EDITOR'S PICK

Bitcoin 609d4d.jpg

Bitcoin Surpasses Realized Worth Of Latest Patrons — Rally Incoming Or Double High?

April 24, 2025
Solana20wallets20hack Id 8358c09f E4e7 43de Bf97 399695cf7c60 Size900.jpg

Why is Solana Up? Blockchain Exercise Soars Following TRUMP Memecoin Launch

January 25, 2025
1721853168 013ihpujcruzdnvbo.jpeg

Forecasting US GDP utilizing Machine Studying and Arithmetic | by Dron Mongia | Jul, 2024

July 24, 2024
1728965921 Ai Shutterstock 2350706053 Special.jpg

Relyance AI Raises $32 Million Collection B Funding to Safeguard AI Innovation within the Enterprise 

October 15, 2024

About Us

Welcome to News AI World, your go-to source for the latest in artificial intelligence news and developments. Our mission is to deliver comprehensive and insightful coverage of the rapidly evolving AI landscape, keeping you informed about breakthroughs, trends, and the transformative impact of AI technologies across industries.

Categories

  • Artificial Intelligence
  • ChatGPT
  • Crypto Coins
  • Data Science
  • Machine Learning

Recent Posts

  • Ought to Bulls Count on A Massive Bounce? ⋆ ZyCrypto
  • Information Visualization Defined (Half 5): Visualizing Time-Sequence Information in Python (Matplotlib, Plotly, and Altair)
  • Why Fintech Begin-Ups Wrestle To Safe The Funding They Want
  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy

© 2024 Newsaiworld.com. All rights reserved.

No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us

© 2024 Newsaiworld.com. All rights reserved.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?