Exemplo n.º 1
0
// 设置图片
void CImageViewDlg::SetImages(unique_ptr<vector<CString> > imageURL)
{
	m_imageURL = std::move(imageURL);
	m_image.resize(m_imageURL->size());

	// 读取图片到m_image
	for (UINT i = 0; i < m_imageURL->size(); i++)
	{
		CString imgName = GetImageName((*m_imageURL)[i]);
		if (PathFileExists(IMG_CACHE_PATH + imgName))
		{
			// 读取图片缓存
			if (!m_image[i].IsNull())
				m_image[i].Destroy();
			m_image[i].Load(IMG_CACHE_PATH + imgName);
		}
		else
		{
			// 下载图片
			unique_ptr<BYTE[]> buffer;
			ULONG size;
			if (HTTPGetRaw((*m_imageURL)[i], &buffer, &size) == NET_SUCCESS)
			{
				ReadImage(buffer.get(), size, m_image[i]);

				CreateDir(IMG_CACHE_PATH);
				CFile file;
				if (file.Open(IMG_CACHE_PATH + imgName, CFile::modeCreate | CFile::modeWrite))
					file.Write(buffer.get(), size);
			}
		}
	}

	UpdateScrollRange();
}
Exemplo n.º 2
0
// 检查图片违规2,下载图片、比较图片
BOOL DoCheckImageIllegal(vector<CString>& imgs, CString& msg)
{
	for (const CString& img : imgs)
	{
		CString imgName = GetImageName(img);

		// 检查缓存结果
		if (g_leagalImage.find(imgName) != g_leagalImage.end())
			continue;
		if (g_illegalImage.find(imgName) != g_illegalImage.end())
			return TRUE;

		// 读取图片
		Mat image;
		if (PathFileExists(IMG_CACHE_PATH + imgName))
		{
			// 读取图片缓存
			ReadImage(IMG_CACHE_PATH + imgName, image);
		}
		else
		{
			// 下载图片
			unique_ptr<BYTE[]> buffer;
			ULONG size;
			if (HTTPGetRaw(img, &buffer, &size, FALSE) == NET_SUCCESS)
			{
				ReadImage(buffer.get(), size, image);

				CreateDir(IMG_CACHE_PATH);
				CFile file;
				if (file.Open(IMG_CACHE_PATH + imgName, CFile::modeCreate | CFile::modeWrite))
					file.Write(buffer.get(), size);
			}
		}

		if (image.data == NULL || image.cols < 30 || image.rows < 30) // 尺寸太小不比较
			continue;
		// 判断和违规图片比较大于阈值
		g_plan.m_optionsLock.Lock();
		for (const NameImage& i : g_plan.m_images)
		{
			if (i.img.cols < 30 || i.img.rows < 30) // 尺寸太小不比较
				continue;
			double mssim = getMSSIM(image, i.img);
			if (mssim > g_plan.m_SSIMThreshold)
			{
				msg.Format(_T("<font color=red> 触发违规图片 </font>%s<font color=red> 相似度%.3lf</font>"),
					(LPCTSTR)i.name, mssim);
				g_illegalImage.insert(imgName);
				g_plan.m_optionsLock.Unlock();
				return TRUE;
			}
		}
		g_leagalImage.insert(imgName);
		g_plan.m_optionsLock.Unlock();
	}

	return FALSE;
}
Exemplo n.º 3
0
// 更换验证码
void CLoginDlg::OnStnClickedStatic4()
{
	CString src = HTTPGet(_T("https://passport.baidu.com/v2/?reggetcodestr&token=") + m_token + _T("&tpl=mn&apiver=v3&tt=1374720914453&callback=bd__cbs__hb302a"), TRUE, NULL, &m_cookie);
	m_verifyStr = GetStringBetween(src, _T("\"verifyStr\" : \""), _T("\""));
	
	// 下载图片
	unique_ptr<BYTE[]> buffer;
	ULONG size;
	HTTPGetRaw(_T("https://passport.baidu.com/cgi-bin/genimage?") + m_verifyStr, &buffer, &size, TRUE, NULL, &m_cookie);
	if (buffer == NULL)
	{
		AfxMessageBox(_T("获取验证码图片失败!"), MB_ICONERROR);
		return;
	}

	ReadImage(buffer.get(), size, m_verifyImage);

	// 显示图片
	m_verifyCodePicture.Invalidate();
}