Android OpenCV:颜色检测给出了奇怪的结果

时间:2017-08-10 07:49:52

标签: java android c++ opencv

我刚学会了如何从OpenCV Java, Getting region of interest from image检测颜色。

最终,我想知道如何检测AA电池(使用和不使用黑色胶带)

我现在正试图检测图片中的电池,但电池并非完全黑,反过来给我带来了奇怪的结果:

enter image description here

我用黑色胶带覆盖电池并再次尝试结果似乎更好但是它在两个单独的部分检测电池:

enter image description here

代码:

--
-- Table structure for table `blog_posts`
--

CREATE TABLE IF NOT EXISTS `blog_posts` (
  `postID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `posterID` int(11) NOT NULL,
  `catID` int(11) NOT NULL,
  `postTitle` varchar(90) DEFAULT NULL,
  `postImg` varchar(255) DEFAULT NULL,
  `postYoutube` varchar(100) DEFAULT NULL,
  `postSlug` varchar(255) DEFAULT NULL,
  `postDesc` text,
  `postCont` text,
  `postViews` int(11) NOT NULL DEFAULT '0',
  `postDate` datetime DEFAULT NULL,
  PRIMARY KEY (`postID`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `blog_posts`
--

INSERT INTO `blog_posts` (`postID`, `posterID`, `catID`, `postTitle`, `postImg`, `postYoutube`, `postSlug`, `postDesc`, `postCont`, `postViews`, `postDate`) VALUES
(1, 1, 1, ' Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.', ' Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.jpg', '', '1/lorem-ipsum-giving', '<p> Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.</p>', '<p> Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.</p>', 1, '2017-08-10 11:46:36'),
(2, 1, 3, ' Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.', ' Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.jpg', '', '2/lorem-ipsum-giving', '<p>Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.</p>', '<p>Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.</p>', 0, '2017-08-10 13:38:57'),
(3, 1, 2, 'Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.', 'Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.jpg', '', '3/moong-dal-halwa', '<p>Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.</p>', '<p>Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.</p>', 0, '2017-08-10 13:39:40'));

-- --------------------------------------------------------

--
-- Table structure for table `blog_posts_tags`
--

CREATE TABLE IF NOT EXISTS `blog_posts_tags` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `post_id` int(11) NOT NULL,
  `tag_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `blog_posts_tags` (`post_id`,`tag_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=31 ;

--
-- Dumping data for table `blog_posts_tags`
--

INSERT INTO `blog_posts_tags` (`id`, `post_id`, `tag_id`) VALUES
(1, 1, 2),
(7, 1, 4),
(9, 1, 3),
(2, 1, 3),
(10, 1, 2),
(8, 1, 5),
(4, 1, 5),
(24, 2, 2),
(25, 3, 5),
(26, 3, 1));

-- --------------------------------------------------------

--
-- Table structure for table `blog_tags`
--

CREATE TABLE IF NOT EXISTS `blog_tags` (
  `tagID` int(11) NOT NULL AUTO_INCREMENT,
  `tagName` varchar(32) NOT NULL,
  `tagUrl` varchar(32) NOT NULL,
  PRIMARY KEY (`tagID`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=61 ;

--
-- Dumping data for table `blog_tags`
--

INSERT INTO `blog_tags` (`tagID`, `tagName`, `tagUrl`) VALUES
(1, 'American Food', 'american-food'),
(2, 'Bakeries', 'bakeries'),
(3, 'Bars', 'bars'),
(4, 'Beef', 'beef'),
(5, 'Cafe', 'cafe');

1 个答案:

答案 0 :(得分:2)

最简单的方法 - 为电池添加颜色标记。其他方式是为您的安装垂直通道设置坚固,可区分的背景(可能是均匀的背光 - 在这种情况下,您应该在白色/高亮度背景上找到黑色/低亮度对象)。如果它不可能并且您有扎实的背景 - 尝试&#34;反转&#34;方法:不要尝试找电池(因为它有很多颜色) - 找到背景(因为它有一种纯色) - 对象有&#34;非背景&#34;颜色可能是电池(你有额外的提示:电池是&#34;垂直&#34;矩形有1/4比例(AAA电池有10.5毫米直径和44.6毫米长度),它大约在图像的垂直中心并且有顶部和底部镀铬高亮度元件等)。