lab 5 part 1

This commit is contained in:
pbiskup 2021-11-28 23:44:09 +01:00
parent dea15e175c
commit e3023e6679
9 changed files with 88 additions and 77 deletions

View File

@ -1,77 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a484c0ac",
"metadata": {},
"outputs": [],
"source": [
"import cv2 as cv"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "733098ae",
"metadata": {},
"outputs": [],
"source": [
"img = cv.imread('img/billboards.jpg')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "22fc2441",
"metadata": {},
"outputs": [],
"source": [
"def click_event(event, x, y, flags, params):\n",
" \n",
" if event == cv2.EVENT_LBUTTONDOWN:\n",
" \n",
" # displaying the coordinates\n",
" # on the Shell\n",
" print(x, ' ', y)\n",
" \n",
" # displaying the coordinates\n",
" # on the image window\n",
" font = cv2.FONT_HERSHEY_SIMPLEX\n",
" cv2.putText(img, str(x) + ',' +\n",
" str(y), (x,y), font,\n",
" 1, (255, 0, 0), 2)\n",
" cv2.imshow('image', img)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "49972565",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

8
lab5/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,15 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="W29" />
<option value="E501" />
<option value="W29" />
<option value="E501" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

10
lab5/.idea/lab5.iml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

4
lab5/.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (lab5)" project-jdk-type="Python SDK" />
</project>

8
lab5/.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/lab5.iml" filepath="$PROJECT_DIR$/.idea/lab5.iml" />
</modules>
</component>
</project>

6
lab5/.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

31
lab5/main.py Normal file
View File

@ -0,0 +1,31 @@
import cv2 as cv
import numpy as np
def click_event(event, x, y, flags, params):
if event == cv.EVENT_LBUTTONDOWN:
# print(x, ' ', y)
cv.circle(img, (int(x), int(y)), 10, [0, 255, 255], -1)
cv.imshow('image', img)
vertexes.append([x, y])
if len(vertexes) == 4:
add_img_in_area()
def add_img_in_area():
# src_points = np.array([[0, 0], [bakery_w - 1, 0], [bakery_w - 1, bakery_h - 1], [0, bakery_h - 1]], dtype=float)
dst_points = np.array(vertexes, dtype=float)
vertexes.clear()
if __name__ == '__main__':
vertexes = []
img = cv.imread('../img/billboards.jpg')
bakery = cv.imread('../img/bakery.jpg')
bakery_h, bakery_w = bakery.shape[0:2]
cv.imshow('image', img)
cv.setMouseCallback('image', click_event)
cv.waitKey(0)
cv.destroyAllWindows()