Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-010
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-010
2021-010
Commits
92427af6
Commit
92427af6
authored
Jul 04, 2021
by
Lakshan Wijewardana W.M.W-IT18132588
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ML files and update ino file
parent
fd144d56
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
3110 additions
and
74 deletions
+3110
-74
Esp-32-wifi_module/test1/test1.ino
Esp-32-wifi_module/test1/test1.ino
+35
-74
ML/Classify org-inorg/.gitignore
ML/Classify org-inorg/.gitignore
+3
-0
ML/Classify org-inorg/Camera_capture_background_remove_and_process.ipynb
...-inorg/Camera_capture_background_remove_and_process.ipynb
+1353
-0
ML/Classify org-inorg/Classify_cucumber_org.ipynb
ML/Classify org-inorg/Classify_cucumber_org.ipynb
+1316
-0
ML/Classify org-inorg/org_Cu.pkl
ML/Classify org-inorg/org_Cu.pkl
+0
-0
ML/Classify org-inorg/organic_inorganic.csv
ML/Classify org-inorg/organic_inorganic.csv
+106
-0
ML/Classify org-inorg/preprocess_extract_dataset_cucumber_org.ipynb
...y org-inorg/preprocess_extract_dataset_cucumber_org.ipynb
+297
-0
No files found.
Esp-32-wifi_module/test1/test1.ino
View file @
92427af6
#include <SparkFunTSL2561.h>
#include <Adafruit_TSL2561_U.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
const
int
ledPin1
=
32
;
const
int
ledPin2
=
33
;
float
ir
;
float
nir
;
float
full
;
float
vis
;
float
NDVI
;
SFE_TSL2561
light
;
// Global variables:
boolean
gain
;
// Gain setting, 0 = X1, 1 = X16;
unsigned
int
ms
;
// Integration ("shutter") time in milliseconds
Adafruit_TSL2561_Unified
tsl
=
Adafruit_TSL2561_Unified
(
TSL2561_ADDR_FLOAT
,
12345
);
void
configureSensor
(
void
)
{
tsl
.
setGain
(
TSL2561_GAIN_1X
);
tsl
.
setIntegrationTime
(
TSL2561_INTEGRATIONTIME_101MS
);
}
void
setup
()
{
// Initialize the Serial port:
pinMode
(
ledPin1
,
OUTPUT
);
pinMode
(
ledPin2
,
OUTPUT
);
Serial
.
begin
(
9600
);
// Initialize the SFE_TSL2561 library
light
.
begin
();
gain
=
0
;
// If time = 0, integration will be 13.7ms
// If time = 1, integration will be 101ms
// If time = 2, integration will be 402ms
// If time = 3, use manual start / stop to perform your own integration
unsigned
char
time
=
2
;
Serial
.
println
(
"Set timing..."
);
light
.
setTiming
(
gain
,
time
,
ms
);
Serial
.
println
(
"Powerup..."
);
light
.
setPowerUp
();
pinMode
(
ledPin1
,
OUTPUT
);
pinMode
(
ledPin2
,
OUTPUT
);
configureSensor
();
Serial
.
begin
(
9600
);
Wire
.
begin
();
}
void
loop
()
{
ms
=
500
;
light
.
manualStart
();
int
ms
=
500
;
delay
(
ms
);
light
.
manualStop
();
digitalWrite
(
ledPin1
,
HIGH
);
digitalWrite
(
ledPin2
,
HIGH
);
unsigned
int
data0
,
data1
;
if
(
light
.
analogRead
(
data0
,
data1
))
{
// getData() returned true, communication was successful
Serial
.
print
(
"data0: "
);
Serial
.
print
(
data0
);
Serial
.
print
(
" data1: "
);
Serial
.
print
(
data1
);
Serial
.
print
(
" red band: "
);
Serial
.
print
(
data0
-
data1
);
double
lux
;
// Resulting lux value
boolean
good
;
// True if neither sensor is saturated
good
=
light
.
getLux
(
gain
,
ms
,
data0
,
data1
,
lux
);
Serial
.
print
(
" lux: "
);
Serial
.
print
(
lux
);
if
(
good
)
Serial
.
println
(
" (good)"
);
else
Serial
.
println
(
" (BAD)"
);
}
else
{
// getData() returned false because of an I2C error, inform the user.
byte
error
=
light
.
getError
();
printError
(
error
);
}
}
void
printError
(
byte
error
)
// If there's an I2C error, this function will
// print out an explanation.
{
Serial
.
print
(
"I2C error: "
);
Serial
.
print
(
error
,
DEC
);
Serial
.
print
(
", "
);
uint16_t
y
=
0
;
uint16_t
z
=
0
;
tsl
.
getLuminosity
(
&
y
,
&
z
);
full
=
y
;
ir
=
z
;
vis
=
full
-
ir
;
nir
=
ir
;
NDVI
=
(
nir
-
vis
)
/
(
nir
+
vis
);
Serial
.
print
(
nir
);
Serial
.
println
(
" 1 (600-1100nm)"
);
Serial
.
print
(
vis
);
Serial
.
println
(
" 1 (Visible)"
);
Serial
.
print
(
NDVI
);
Serial
.
println
(
" 1 (NDVI)"
);
Serial
.
println
(
""
);
}
ML/Classify org-inorg/.gitignore
0 → 100644
View file @
92427af6
.ipynb_checkpoints/
organic dataset/
mobile captures/
\ No newline at end of file
ML/Classify org-inorg/Camera_capture_background_remove_and_process.ipynb
0 → 100644
View file @
92427af6
This diff is collapsed.
Click to expand it.
ML/Classify org-inorg/Classify_cucumber_org.ipynb
0 → 100644
View file @
92427af6
This diff is collapsed.
Click to expand it.
ML/Classify org-inorg/org_Cu.pkl
0 → 100644
View file @
92427af6
File added
ML/Classify org-inorg/organic_inorganic.csv
0 → 100644
View file @
92427af6
This diff is collapsed.
Click to expand it.
ML/Classify org-inorg/preprocess_extract_dataset_cucumber_org.ipynb
0 → 100644
View file @
92427af6
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import cv2\n",
"import numpy as np\n",
"import pandas as pd\n",
"import mahotas as mht\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"dataset_path = \"organic dataset\"\n",
"img_files = os.listdir(dataset_path)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"def create_dataset():\n",
" names = ['area','perimeter','physiological_length','physiological_width','aspect_ratio','rectangularity','circularity', \\\n",
" 'mean_r','mean_g','mean_b','stddev_r','stddev_g','stddev_b', \\\n",
" 'contrast','correlation','inverse_difference_moments','entropy'\n",
" ]\n",
" df = pd.DataFrame([], columns=names)\n",
" for file in img_files:\n",
" imgpath = dataset_path + \"\\\\\" + file\n",
" main_img = cv2.imread(imgpath)\n",
" \n",
" #Preprocessing\n",
" img = cv2.cvtColor(main_img, cv2.COLOR_BGR2RGB)\n",
" gr_scale = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)\n",
" blur = cv2.GaussianBlur(gr_scale, (5,5),0)\n",
" ret_otsu,im_bw_otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)\n",
" kernel = np.ones((50,50),np.uint8)\n",
" closing = cv2.morphologyEx(im_bw_otsu, cv2.MORPH_CLOSE, kernel)\n",
" \n",
" #Shape\n",
" contours, _ = cv2.findContours(closing,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)\n",
" cnt = contours[0]\n",
" M = cv2.moments(cnt)\n",
" area = cv2.contourArea(cnt)\n",
" perimeter = cv2.arcLength(cnt,True)\n",
" x,y,w,h = cv2.boundingRect(cnt)\n",
" aspect_ratio = float(w)/h\n",
" rectangularity = w*h/area\n",
" circularity = ((perimeter)**2)/area\n",
" \n",
" #Color\n",
" red_channel = img[:,:,0]\n",
" green_channel = img[:,:,1]\n",
" blue_channel = img[:,:,2]\n",
" blue_channel[blue_channel == 255] = 0\n",
" green_channel[green_channel == 255] = 0\n",
" red_channel[red_channel == 255] = 0\n",
" \n",
" red_mean = np.mean(red_channel)\n",
" green_mean = np.mean(green_channel)\n",
" blue_mean = np.mean(blue_channel)\n",
" \n",
" red_std = np.std(red_channel)\n",
" green_std = np.std(green_channel)\n",
" blue_std = np.std(blue_channel)\n",
" \n",
" #Texture\n",
" textures = mht.features.haralick(gr_scale)\n",
" ht_mean = textures.mean(axis=0)\n",
" contrast = ht_mean[1]\n",
" correlation = ht_mean[2]\n",
" inverse_diff_moments = ht_mean[4]\n",
" entropy = ht_mean[8]\n",
" \n",
" vector = [area,perimeter,w,h,aspect_ratio,rectangularity,circularity,\\\n",
" red_mean,green_mean,blue_mean,red_std,green_std,blue_std,\\\n",
" contrast,correlation,inverse_diff_moments,entropy\n",
" ]\n",
" \n",
" df_temp = pd.DataFrame([vector],columns=names)\n",
" df = df.append(df_temp)\n",
" print(file)\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"101.jpg\n",
"102.jpg\n",
"103.jpg\n",
"104.jpg\n",
"105.jpg\n",
"106.jpg\n",
"107.jpg\n",
"108.jpg\n",
"109.jpg\n",
"110.jpg\n",
"111.jpg\n",
"112.jpg\n",
"113.jpg\n",
"114.jpg\n",
"115.jpg\n",
"116.jpg\n",
"117.jpg\n",
"118.jpg\n",
"120.jpg\n",
"121.jpg\n",
"122.jpg\n",
"123.jpg\n",
"124.jpg\n",
"125.jpg\n",
"126.jpg\n",
"127.jpg\n",
"128.jpg\n",
"129.jpg\n",
"130.jpg\n",
"131.jpg\n",
"132.jpg\n",
"133.jpg\n",
"134.jpg\n",
"135.jpg\n",
"136.jpg\n",
"137.jpg\n",
"138.jpg\n",
"139.jpg\n",
"140.jpg\n",
"141.jpg\n",
"142.jpg\n",
"143.jpg\n",
"144.jpg\n",
"145.jpg\n",
"146.jpg\n",
"147.jpg\n",
"148.jpg\n",
"149.jpg\n",
"150.jpg\n",
"151.jpg\n",
"152.jpg\n",
"153.jpg\n",
"154.jpg\n",
"155.jpg\n",
"156.jpg\n",
"157.jpg\n",
"158.jpg\n",
"159.jpg\n",
"160.jpg\n",
"161.jpg\n",
"162.jpg\n",
"163.jpg\n",
"164.jpg\n",
"165.jpg\n",
"166.jpg\n",
"167.jpg\n",
"168.jpg\n",
"169.jpg\n",
"170.jpg\n",
"171.jpg\n",
"172.jpg\n",
"173.jpg\n",
"174.jpg\n",
"175.jpg\n",
"176.jpg\n",
"177.jpg\n",
"178.jpg\n",
"179.jpg\n",
"180.jpg\n",
"181.jpg\n",
"182.jpg\n",
"183.jpg\n",
"184.jpg\n",
"185.jpg\n",
"186.jpg\n",
"187.jpg\n",
"188.jpg\n",
"189.jpg\n",
"190.jpg\n",
"191.jpg\n",
"192.jpg\n",
"193.jpg\n",
"194.jpg\n",
"195.jpg\n",
"196.jpg\n",
"197.jpg\n",
"198.jpg\n",
"199.jpg\n",
"200.jpg\n",
"201.jpg\n",
"202.jpg\n",
"203.jpg\n",
"204.jpg\n",
"205.jpg\n",
"206.jpg\n"
]
}
],
"source": [
"dataset = create_dataset()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(105, 17)"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dataset.shape"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.frame.DataFrame"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(dataset)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"dataset.to_csv(\"organic_inorganic.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"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": 2
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment