Skip to content

Commit

Permalink
Corected Input and Formatting
Browse files Browse the repository at this point in the history
I wonder how many times I will need to do this
  • Loading branch information
zappybiby committed Jan 21, 2017
1 parent 06fb7bb commit bced2f5
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 168 deletions.
Binary file modified ets2_auto_driving.sdf
Binary file not shown.
Binary file modified ets2_auto_driving.v12.suo
Binary file not shown.
102 changes: 51 additions & 51 deletions ets2_auto_driving/IPM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ using namespace cv;
using namespace std;

// Public
IPM::IPM( const cv::Size& _origSize, const cv::Size& _dstSize, const std::vector<cv::Point2f>& _origPoints, const std::vector<cv::Point2f>& _dstPoints )
IPM::IPM(const cv::Size& _origSize, const cv::Size& _dstSize, const std::vector<cv::Point2f>& _origPoints, const std::vector<cv::Point2f>& _dstPoints)
: m_origSize(_origSize), m_dstSize(_dstSize), m_origPoints(_origPoints), m_dstPoints(_dstPoints)
{
assert( m_origPoints.size() == 4 && m_dstPoints.size() == 4 && "Orig. points and Dst. points must vectors of 4 points" );
m_H = getPerspectiveTransform( m_origPoints, m_dstPoints );
assert(m_origPoints.size() == 4 && m_dstPoints.size() == 4 && "Orig. points and Dst. points must vectors of 4 points");
m_H = getPerspectiveTransform(m_origPoints, m_dstPoints);
m_H_inv = m_H.inv();
createMaps();

createMaps();
}
void IPM::drawPoints( const std::vector<cv::Point2f>& _points, cv::Mat& _img ) const
void IPM::drawPoints(const std::vector<cv::Point2f>& _points, cv::Mat& _img) const
{
assert(_points.size() == 4);

line(_img, Point(static_cast<int>(_points[0].x), static_cast<int>(_points[0].y)), Point(static_cast<int>(_points[3].x), static_cast<int>(_points[3].y)), CV_RGB( 205,205,0), 2);
line(_img, Point(static_cast<int>(_points[2].x), static_cast<int>(_points[2].y)), Point(static_cast<int>(_points[3].x), static_cast<int>(_points[3].y)), CV_RGB( 205,205,0), 2);
line(_img, Point(static_cast<int>(_points[0].x), static_cast<int>(_points[0].y)), Point(static_cast<int>(_points[1].x), static_cast<int>(_points[1].y)), CV_RGB( 205,205,0), 2);
line(_img, Point(static_cast<int>(_points[2].x), static_cast<int>(_points[2].y)), Point(static_cast<int>(_points[1].x), static_cast<int>(_points[1].y)), CV_RGB( 205,205,0), 2);
for(size_t i=0; i<_points.size(); i++)
line(_img, Point(static_cast<int>(_points[0].x), static_cast<int>(_points[0].y)), Point(static_cast<int>(_points[3].x), static_cast<int>(_points[3].y)), CV_RGB(205, 205, 0), 2);
line(_img, Point(static_cast<int>(_points[2].x), static_cast<int>(_points[2].y)), Point(static_cast<int>(_points[3].x), static_cast<int>(_points[3].y)), CV_RGB(205, 205, 0), 2);
line(_img, Point(static_cast<int>(_points[0].x), static_cast<int>(_points[0].y)), Point(static_cast<int>(_points[1].x), static_cast<int>(_points[1].y)), CV_RGB(205, 205, 0), 2);
line(_img, Point(static_cast<int>(_points[2].x), static_cast<int>(_points[2].y)), Point(static_cast<int>(_points[1].x), static_cast<int>(_points[1].y)), CV_RGB(205, 205, 0), 2);
for (size_t i = 0; i < _points.size(); i++)
{
circle(_img, Point(static_cast<int>(_points[i].x), static_cast<int>(_points[i].y)), 2, CV_RGB(238,238,0), -1);
circle(_img, Point(static_cast<int>(_points[i].x), static_cast<int>(_points[i].y)), 5, CV_RGB(255,255,255), 2);
circle(_img, Point(static_cast<int>(_points[i].x), static_cast<int>(_points[i].y)), 2, CV_RGB(238, 238, 0), -1);
circle(_img, Point(static_cast<int>(_points[i].x), static_cast<int>(_points[i].y)), 5, CV_RGB(255, 255, 255), 2);
}
}
void IPM::getPoints(vector<Point2f>& _origPts, vector<Point2f>& _ipmPts)
Expand All @@ -42,68 +42,68 @@ void IPM::applyHomographyInv(const Mat& _inputImg, Mat& _dstImg, int _borderMode
// Generate IPM image from src
remap(_inputImg, _dstImg, m_mapX, m_mapY, INTER_LINEAR, _borderMode);//, BORDER_CONSTANT, Scalar(0,0,0,0));
}
Point2d IPM::applyHomography( const Point2d& _point )
Point2d IPM::applyHomography(const Point2d& _point)
{
return applyHomography( _point, m_H );
return applyHomography(_point, m_H);
}
Point2d IPM::applyHomographyInv( const Point2d& _point )
Point2d IPM::applyHomographyInv(const Point2d& _point)
{
return applyHomography( _point, m_H_inv );
return applyHomography(_point, m_H_inv);
}
Point2d IPM::applyHomography( const Point2d& _point, const Mat& _H )
Point2d IPM::applyHomography(const Point2d& _point, const Mat& _H)
{
Point2d ret = Point2d( -1, -1 );
const double u = _H.at<double>(0,0) * _point.x + _H.at<double>(0,1) * _point.y + _H.at<double>(0,2);
const double v = _H.at<double>(1,0) * _point.x + _H.at<double>(1,1) * _point.y + _H.at<double>(1,2);
const double s = _H.at<double>(2,0) * _point.x + _H.at<double>(2,1) * _point.y + _H.at<double>(2,2);
if ( s != 0 )
Point2d ret = Point2d(-1, -1);

const double u = _H.at<double>(0, 0) * _point.x + _H.at<double>(0, 1) * _point.y + _H.at<double>(0, 2);
const double v = _H.at<double>(1, 0) * _point.x + _H.at<double>(1, 1) * _point.y + _H.at<double>(1, 2);
const double s = _H.at<double>(2, 0) * _point.x + _H.at<double>(2, 1) * _point.y + _H.at<double>(2, 2);
if (s != 0)
{
ret.x = ( u / s );
ret.y = ( v / s );
ret.x = (u / s);
ret.y = (v / s);
}
return ret;
return ret;
}
Point3d IPM::applyHomography( const Point3d& _point )
Point3d IPM::applyHomography(const Point3d& _point)
{
return applyHomography( _point, m_H );
return applyHomography(_point, m_H);
}
Point3d IPM::applyHomographyInv( const Point3d& _point )
Point3d IPM::applyHomographyInv(const Point3d& _point)
{
return applyHomography( _point, m_H_inv );
return applyHomography(_point, m_H_inv);
}
Point3d IPM::applyHomography( const Point3d& _point, const cv::Mat& _H )
Point3d IPM::applyHomography(const Point3d& _point, const cv::Mat& _H)
{
Point3d ret = Point3d( -1, -1, 1 );
const double u = _H.at<double>(0,0) * _point.x + _H.at<double>(0,1) * _point.y + _H.at<double>(0,2) * _point.z;
const double v = _H.at<double>(1,0) * _point.x + _H.at<double>(1,1) * _point.y + _H.at<double>(1,2) * _point.z;
const double s = _H.at<double>(2,0) * _point.x + _H.at<double>(2,1) * _point.y + _H.at<double>(2,2) * _point.z;
if ( s != 0 )
Point3d ret = Point3d(-1, -1, 1);

const double u = _H.at<double>(0, 0) * _point.x + _H.at<double>(0, 1) * _point.y + _H.at<double>(0, 2) * _point.z;
const double v = _H.at<double>(1, 0) * _point.x + _H.at<double>(1, 1) * _point.y + _H.at<double>(1, 2) * _point.z;
const double s = _H.at<double>(2, 0) * _point.x + _H.at<double>(2, 1) * _point.y + _H.at<double>(2, 2) * _point.z;
if (s != 0)
{
ret.x = ( u / s );
ret.y = ( v / s );
ret.x = (u / s);
ret.y = (v / s);
}
else
ret.z = 0;
return ret;
return ret;
}

// Private
void IPM::createMaps()
{
{
// Create remap images
m_mapX.create(m_dstSize, CV_32F);
m_mapY.create(m_dstSize, CV_32F);
//#pragma omp parallel for schedule(dynamic)
for( int j = 0; j < m_dstSize.height; ++j )
for (int j = 0; j < m_dstSize.height; ++j)
{
float* ptRowX = m_mapX.ptr<float>(j);
float* ptRowY = m_mapY.ptr<float>(j);
//#pragma omp parallel for schedule(dynamic)
for( int i = 0; i < m_dstSize.width; ++i )
for (int i = 0; i < m_dstSize.width; ++i)
{
Point2f pt = applyHomography( Point2f( static_cast<float>(i), static_cast<float>(j) ), m_H_inv );
Point2f pt = applyHomography(Point2f(static_cast<float>(i), static_cast<float>(j)), m_H_inv);
ptRowX[i] = pt.x;
ptRowY[i] = pt.y;
}
Expand All @@ -113,16 +113,16 @@ void IPM::createMaps()
m_invMapY.create(m_origSize, CV_32F);

//#pragma omp parallel for schedule(dynamic)
for( int j = 0; j < m_origSize.height; ++j )
for (int j = 0; j < m_origSize.height; ++j)
{
float* ptRowX = m_invMapX.ptr<float>(j);
float* ptRowY = m_invMapY.ptr<float>(j);
//#pragma omp parallel for schedule(dynamic)
for( int i = 0; i < m_origSize.width; ++i )
//#pragma omp parallel for schedule(dynamic)
for (int i = 0; i < m_origSize.width; ++i)
{
Point2f pt = applyHomography( Point2f( static_cast<float>(i), static_cast<float>(j) ), m_H );
Point2f pt = applyHomography(Point2f(static_cast<float>(i), static_cast<float>(j)), m_H);
ptRowX[i] = pt.x;
ptRowY[i] = pt.y;
ptRowY[i] = pt.y;
}
}
}
}
12 changes: 10 additions & 2 deletions ets2_auto_driving/ets2_auto_driving.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros">
<NuGetPackageImportStamp>b7659eb1</NuGetPackageImportStamp>
<NuGetPackageImportStamp>06b11406</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(IncludePath)</IncludePath>
Expand Down Expand Up @@ -99,7 +99,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\opencv\opencv\build\include\opencv2;C:\opencv\opencv\build\include;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opencv_calib3d310.lib;opencv_core310.lib;opencv_features2d310.lib;opencv_flann310.lib;opencv_highgui310.lib;opencv_imgcodecs310.lib;opencv_imgproc310.lib;opencv_ml310.lib;opencv_objdetect310.lib;opencv_photo310.lib;opencv_shape310.lib;opencv_stitching310.lib;opencv_superres310.lib;opencv_ts310.lib;opencv_video310.lib;opencv_videoio310.lib;opencv_videostab310.lib;opencv_viz310.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opencv_calib3d310.lib;opencv_core310.lib;opencv_features2d310.lib;opencv_flann310.lib;opencv_highgui310.lib;opencv_imgcodecs310.lib;opencv_imgproc310.lib;opencv_ml310.lib;opencv_objdetect310.lib;opencv_photo310.lib;opencv_shape310.lib;opencv_stitching310.lib;opencv_superres310.lib;opencv_ts310.lib;opencv_video310.lib;opencv_videoio310.lib;opencv_videostab310.lib;opencv_viz310.lib;opencv_calib3d310d.lib;opencv_core310d.lib;opencv_features2d310d.lib;opencv_flann310d.lib;opencv_highgui310d.lib;opencv_imgcodecs310d.lib;opencv_imgproc310d.lib;opencv_ml310d.lib;opencv_objdetect310d.lib;opencv_photo310d.lib;opencv_shape310d.lib;opencv_stitching310d.lib;opencv_superres310d.lib;opencv_ts310d.lib;opencv_video310d.lib;opencv_videoio310d.lib;opencv_videostab310d.lib;opencv_viz310d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary>
</ImportLibrary>
</Link>
Expand Down Expand Up @@ -176,12 +176,20 @@
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 7.5.targets" />
<Import Project="..\packages\opencvcuda-release.redist.3.1.0\build\native\opencvcuda-release.redist.targets" Condition="Exists('..\packages\opencvcuda-release.redist.3.1.0\build\native\opencvcuda-release.redist.targets')" />
<Import Project="..\packages\opencvcuda-release.3.1.0\build\native\opencvcuda-release.targets" Condition="Exists('..\packages\opencvcuda-release.3.1.0\build\native\opencvcuda-release.targets')" />
<Import Project="..\packages\opencvdefault.redist.3.1.0\build\native\opencvdefault.redist.targets" Condition="Exists('..\packages\opencvdefault.redist.3.1.0\build\native\opencvdefault.redist.targets')" />
<Import Project="..\packages\opencvdefault.3.1.0\build\native\opencvdefault.targets" Condition="Exists('..\packages\opencvdefault.3.1.0\build\native\opencvdefault.targets')" />
<Import Project="..\packages\opencvcuda-debug.redist.3.1.0\build\native\opencvcuda-debug.redist.targets" Condition="Exists('..\packages\opencvcuda-debug.redist.3.1.0\build\native\opencvcuda-debug.redist.targets')" />
<Import Project="..\packages\opencvcuda-debug.3.1.0\build\native\opencvcuda-debug.targets" Condition="Exists('..\packages\opencvcuda-debug.3.1.0\build\native\opencvcuda-debug.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\opencvcuda-release.redist.3.1.0\build\native\opencvcuda-release.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\opencvcuda-release.redist.3.1.0\build\native\opencvcuda-release.redist.targets'))" />
<Error Condition="!Exists('..\packages\opencvcuda-release.3.1.0\build\native\opencvcuda-release.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\opencvcuda-release.3.1.0\build\native\opencvcuda-release.targets'))" />
<Error Condition="!Exists('..\packages\opencvdefault.redist.3.1.0\build\native\opencvdefault.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\opencvdefault.redist.3.1.0\build\native\opencvdefault.redist.targets'))" />
<Error Condition="!Exists('..\packages\opencvdefault.3.1.0\build\native\opencvdefault.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\opencvdefault.3.1.0\build\native\opencvdefault.targets'))" />
<Error Condition="!Exists('..\packages\opencvcuda-debug.redist.3.1.0\build\native\opencvcuda-debug.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\opencvcuda-debug.redist.3.1.0\build\native\opencvcuda-debug.redist.targets'))" />
<Error Condition="!Exists('..\packages\opencvcuda-debug.3.1.0\build\native\opencvcuda-debug.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\opencvcuda-debug.3.1.0\build\native\opencvcuda-debug.targets'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion ets2_auto_driving/hwnd2mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Mat hwnd2mat(HWND hWnd) {
RECT windowsize; // get the height and width of the screen
GetClientRect(hWnd, &windowsize);

srcheight = windowsize.bottom ;// change this to whatever size you want to resize to
srcheight = windowsize.bottom;// change this to whatever size you want to resize to
srcwidth = windowsize.right;
height = windowsize.bottom; // change this to whatever size you want to resize to
width = windowsize.right;
Expand Down
33 changes: 20 additions & 13 deletions ets2_auto_driving/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ int main() {
//HWND hWnd = FindWindow("Photo_Light", NULL);
Mat image, outputImg; // Creates two Mats, image and outputImg. outputImg is used for showing what the program sees to user in a new window.
hwnd2mat(hWnd).copyTo(image);

// Mat to GpuMat
//cuda::GpuMat imageGPU;
//imageGPU.upload(image);
Expand All @@ -51,8 +50,8 @@ int main() {
RECT windowsize;
GetClientRect(hWnd, &windowsize);

height = 768; // change this to whatever size you want to resize to
width = 1024;
height = windowsize.bottom; // change this to whatever size you want to resize to
width = windowsize.right;

// The 4-points at the input image
vector<Point2f> origPoints;
Expand Down Expand Up @@ -88,8 +87,8 @@ int main() {
cv::Mat sobel;
cv::Mat contours;
cv::resize(outputImg, outputImg, cv::Size(320, 240));
//cv::cvtColor(outputImg, gray, COLOR_RGB2GRAY);
cv::cvtColor(outputImg, gray, COLOR_BGR2GRAY); // testing using BGR instead of RGB (https://stackoverflow.com/questions/7461075)
cv::cvtColor(outputImg, gray, COLOR_RGB2GRAY);
//cv::cvtColor(outputImg, gray, COLOR_BGR2GRAY); // testing using BGR instead of RGB (https://stackoverflow.com/questions/7461075)
cv::blur(gray, blur, cv::Size(10, 10));
cv::Sobel(blur, sobel, blur.depth(), 1, 0, 3, 0.5, 127);
cv::threshold(sobel, contours, 145, 255, CV_THRESH_BINARY);
Expand Down Expand Up @@ -175,14 +174,22 @@ int main() {
ip.ki.dwExtraInfo = 0;
//while (1)
//{
ip.ki.wScan = 0x74;
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; // Releases 0x74
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
ip.ki.wScan = 0x44; // Releases 'D'
SendInput(1, &ip, sizeof(ip));
Sleep(100);

ip.ki.wScan = 0x41;
ip.ki.dwFlags = KEYEVENTF_SCANCODE; // Pushes 'A'
SendInput(1, &ip, sizeof(ip));
Sleep(100);

ip.ki.dwFlags = KEYEVENTF_SCANCODE;
ip.ki.wScan = 0x41; // Presses 'A'
ip.ki.wScan = 0x41;
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; // Releases 'A'
SendInput(1, &ip, sizeof(ip));
Sleep(100);


//}
}
else if (left + right > -50 && left + right < 50){
Expand Down Expand Up @@ -230,18 +237,18 @@ int main() {
ip.ki.dwExtraInfo = 0;
//while (1)
//{
ip.ki.wScan = 0x44;
ip.ki.dwFlags = KEYEVENTF_SCANCODE; // Presses 0x41
ip.ki.wScan = 0x41;
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; // Releases 'A'
SendInput(1, &ip, sizeof(ip));
Sleep(100);

ip.ki.wScan = 0x44;
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; // Releases 'A'
ip.ki.dwFlags = KEYEVENTF_SCANCODE; // Presses 'A'
SendInput(1, &ip, sizeof(ip));
Sleep(100);

ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
ip.ki.wScan = 0x41; // Presses 'A'
ip.ki.wScan = 0x44; // Releases 'A'
SendInput(1, &ip, sizeof(ip));
Sleep(100);
// keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
Expand Down
4 changes: 4 additions & 0 deletions ets2_auto_driving/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="opencvcuda-debug" version="3.1.0" targetFramework="Native" />
<package id="opencvcuda-debug.redist" version="3.1.0" targetFramework="Native" />
<package id="opencvcuda-release" version="3.1.0" targetFramework="Native" />
<package id="opencvcuda-release.redist" version="3.1.0" targetFramework="Native" />
<package id="opencvdefault" version="3.1.0" targetFramework="Native" />
<package id="opencvdefault.redist" version="3.1.0" targetFramework="Native" />
</packages>
Binary file modified ets2_auto_driving/vc120.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit bced2f5

Please sign in to comment.