mirror of
https://github.com/NanjingForestryUniversity/supermachine-tobacco.git
synced 2025-11-08 14:23:55 +00:00
膨胀
This commit is contained in:
parent
f7c88d3c2a
commit
f52c8943e1
@ -40,7 +40,7 @@
|
||||
"color_dict = {(0, 0, 255): \"yangeng\", (255, 0, 0): 'beijing',(0, 255, 0): \"zibian\"} # 颜色对应的类别\n",
|
||||
"# color_dict = {(0, 0, 255): \"yangeng\"}\n",
|
||||
"# color_dict = {(255, 0, 0): 'beijing'}\n",
|
||||
"color_dict = {(0, 255, 0): \"zibian\"}\n",
|
||||
"# color_dict = {(0, 255, 0): \"zibian\"}\n",
|
||||
"label_index = {\"yangeng\": 1, \"beijing\": 0, \"zibian\":2} # 类别对应的序号\n",
|
||||
"show_samples = False # 是否展示样本\n",
|
||||
"\n",
|
||||
|
||||
@ -14,7 +14,7 @@ color_dict = {(0, 0, 255): "yangeng", (255, 0, 0): 'beijing', (0, 255, 0): "zibi
|
||||
# color_dict = {(255, 0, 0): 'beijing'}
|
||||
# color_dict = {(0, 255, 0): "zibian"}
|
||||
label_index = {"yangeng": 1, "beijing": 0, "zibian": 2} # 类别对应的序号
|
||||
show_samples = False # 是否展示样本
|
||||
show_samples = True # 是否展示样本
|
||||
|
||||
# 定义一些训练量
|
||||
threshold = 5 # 正样本周围多大范围内的还算是正样本
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 44,
|
||||
"execution_count": 17,
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import datetime\n",
|
||||
@ -25,7 +25,7 @@
|
||||
"import numpy as np\n",
|
||||
"import pickle\n",
|
||||
"from sklearn.tree import DecisionTreeClassifier\n",
|
||||
"%matplotlib notebook\n",
|
||||
"# %matplotlib notebook\n",
|
||||
"from main_test import virtual_main\n",
|
||||
"from models import AnonymousColorDetector\n",
|
||||
"from utils import lab_scatter"
|
||||
@ -39,11 +39,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"execution_count": 18,
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"img_path = r\"C:\\Users\\FEIJINTI\\Desktop\\721\\zazhi\\Image_2022_0721_1351_38_946-002034.bmp\"\n",
|
||||
"model_path = [\"models/beijing_dt_2022-07-21_16-44.model\", \"models/tobacco_dt_2022-07-21_16-30.model\",\"models/zibian_dt_2022-07-21_16-45.model\"]"
|
||||
"model_path = [\"models/beijing_dt_2022-07-21_16-44.model\", \"models/tobacco_dt_2022-07-21_16-30.model\",\"models/zibian_dt_2022-07-21_16-45.model\",\"dt_2022-07-21_17-19.model\"]"
|
||||
],
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
@ -54,7 +54,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 46,
|
||||
"execution_count": 19,
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"img = cv2.imread(img_path)[:, :, ::-1]\n",
|
||||
@ -71,11 +71,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 47,
|
||||
"execution_count": 20,
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"t_detector = AnonymousColorDetector(file_path=model_path[1])\n",
|
||||
"t_result = t_detector.predict(img).astype(np.uint8)"
|
||||
"t_result = t_detector.predict(img).astype(np.uint8)\n",
|
||||
"t_result = cv2.dilate(t_result, kernel = np.ones((3, 3), np.uint8))"
|
||||
],
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
@ -86,7 +87,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 48,
|
||||
"execution_count": 21,
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"z_detector = AnonymousColorDetector(file_path=model_path[2])\n",
|
||||
@ -101,10 +102,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 49,
|
||||
"execution_count": 22,
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"result = 1 - (b_result | t_result | z_result)"
|
||||
"s_detector = AnonymousColorDetector(file_path=model_path[3])\n",
|
||||
"s_result = s_detector.predict(img).astype(np.uint8)"
|
||||
],
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
@ -115,7 +117,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 50,
|
||||
"execution_count": 25,
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"result = 1 - (b_result | t_result)"
|
||||
],
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
@ -128,26 +144,20 @@
|
||||
{
|
||||
"data": {
|
||||
"text/plain": "<IPython.core.display.HTML object>",
|
||||
"text/html": "<div id='71e0e832-f293-40bc-9913-301125493d2e'></div>"
|
||||
"text/html": "<div id='45f22664-39a5-478c-8758-331c7e98de1a'></div>"
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": "<matplotlib.image.AxesImage at 0x24e8faaa440>"
|
||||
},
|
||||
"execution_count": 50,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"fig,axs = plt.subplots(4,1)\n",
|
||||
"fig,axs = plt.subplots(5,1)\n",
|
||||
"axs[0].imshow(b_result)\n",
|
||||
"axs[1].imshow(t_result)\n",
|
||||
"axs[2].imshow(z_result)\n",
|
||||
"axs[3].imshow(result)"
|
||||
"axs[3].imshow(result)\n",
|
||||
"axs[4].imshow(1-s_result)\n",
|
||||
"plt.savefig(\"1.png\",dpi=900)"
|
||||
],
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
@ -158,7 +168,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 50,
|
||||
"execution_count": 24,
|
||||
"outputs": [],
|
||||
"source": [],
|
||||
"metadata": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user