-
Homepage
-
Harris Corner Detection Technique Homework Help
Finding Data Points of an Image Using Harris Corner Detection Technique
Use Harris corner detection technique to find the data points (key points) of the image. Write a program to perform K-means clustering technique using the strongest 100 points of part 1. You need to create your own function/code for this part (K-mean algorithm).
• Compare the outcomes of multiple runs with different values for K and choose the best one based on a predefined criterion.
• Display the original image with the best detected clusters on it (use different colors).
• Draw a bounding box for each cluster of the data points of part 2.
You may use the built-in function/library (cv2.rectangle()) or any other one for this part. Display the original image with the bounding boxes on it (use different colors).
Cornerstone Detection code 1
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"importnumpy as np\n",
"import cv2 as cv\n",
"importmatplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Q1. Detect corner using Harris detector"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"file = 'D:/freelancer/corner/image.jpg'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"im = cv.imread(file)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"gray = cv.cvtColor(im, cv.COLOR_BGR2GRAY)\n",
"gray = np.float32(gray)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"dst = cv.cornerHarris(gray, 2, 3, 0.04)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"im_new = im.copy()\n",
"im_new[dst>0.01*dst.max()]=[255,0,0]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
Cornerstone Code Solution 2
{
"cells": [
{
"cell_type": "code",
"execution_count": 250,
"metadata": {},
"outputs": [],
"source": [
"importnumpy as np\n",
"import cv2 as cv\n",
"importmatplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Detect corner using Harris detector"
]
},
{
"cell_type": "code",
"execution_count": 281,
"metadata": {},
"outputs": [],
"source": [
"file = 'D:/freelancer/corner/image.jpg'"
]
},
{
"cell_type": "code",
"execution_count": 282,
"metadata": {},
"outputs": [],
"source": [
"im = cv.imread(file)"
]
},
{
"cell_type": "code",
"execution_count": 283,
"metadata": {},
"outputs": [],
"source": [
"gray = cv.cvtColor(im, cv.COLOR_BGR2GRAY)\n",
"gray = np.float32(gray)"
]
},
{
"cell_type": "code",
"execution_count": 284,
"metadata": {},
"outputs": [],
"source": [
"dst = cv.cornerHarris(gray, 2, 3, 0.04)"
]
},
{
"cell_type": "code",
"execution_count": 285,
"metadata": {},
"outputs": [],
"source": [
"im_new = im.copy()\n",
"im_new[dst>0.01*dst.max()]=[255,0,0]"
]
},
{
"cell_type": "code",
"execution_count": 286,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 286,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {