1 | initial version |
That's not an answer. I am not able to reproduce your issue using this program but I think I don't understand your transformation. My program is :
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
struct ZoomPos {
Point p;
bool newPt;
int zoom;
int typeInter;
bool inter;
};
void AjouteGlissiere(String nomGlissiere, String nomFenetre, int minGlissiere, int maxGlissiere, int valeurDefaut, int *valGlissiere, void(*f)(int, void *), void *r)
{
createTrackbar(nomGlissiere, nomFenetre, valGlissiere, 1, f, r);
setTrackbarMin(nomGlissiere, nomFenetre, minGlissiere);
setTrackbarMax(nomGlissiere, nomFenetre, maxGlissiere);
setTrackbarPos(nomGlissiere, nomFenetre, valeurDefaut);
}
void onZoom(int event, int x, int y, int flags, void *userdata)
{
ZoomPos *z=(ZoomPos*)userdata;
if (event== EVENT_LBUTTONDOWN)
{
z->p = Point(x,y);
z->newPt=true;
}
else
z->newPt = false;
}
void MAJInter(int x, void * userdata)
{
ZoomPos *z = (ZoomPos*)userdata;
z->inter=true;
}
int main() {
ifstream fs;
fs.open("pp_sel_00000.fit",ios::binary);
if (!fs.is_open())
{
cout<<"PB";
return 0;
}
fs.seekg(0, ios_base::end);
int nb=fs.tellg();
int nb2=4008*2672*2;
cout<< nb+ -11 * 256 + 64<<" =? "<<nb2<<endl;
fs.seekg(11*256+64, ios_base::beg);
vector<char> v(nb2);
fs.read(v.data(),nb2);
Mat h=(Mat_<double>(3,3)<< -0.99974,- 0.00299,+ 4002.14396, +0.00239,- 0.99964,+ 2673.06210, -0.00000,- 0.00000, 1.00000);
for (int i = 0; i < v.size(); i += 2)
{
swap(v[i],v[i+1]);
}
Mat imgOriginal(2672,4008,CV_16SC1,v.data());
Mat img;
Mat img2;
ZoomPos z;
img=imgOriginal.clone();
resize(img,img,img.size()*2);
warpPerspective(img, img2, h, img.size(), CV_INTER_LANCZOS4);
resize(img2, img, imgOriginal.size());
namedWindow("test", WINDOW_NORMAL);
int code=0;
imshow("test",img);
z.p =Point(0,0);z.newPt = false; z.zoom = 1;z.inter=false;z.typeInter= CV_INTER_LANCZOS4;
AjouteGlissiere("Interpolation", "test", 0, CV_INTER_LANCZOS4, CV_INTER_LANCZOS4, &z.typeInter,MAJInter,&z);
setMouseCallback("test",onZoom,&z);
Mat x;
bool modifZoom=false;
while (code != 27)
{
code = waitKey(10);
switch (code){
case '+' :
if (z.zoom < 16)
{
modifZoom=true;
z.zoom += 1;
}
break;
case '-' :
if (z.zoom>=2)
{
modifZoom = true;
z.zoom -= 1;
}
break;
}
if (z.inter)
{
img = imgOriginal.clone();
resize(img, img, img.size() * 2);
warpPerspective(img, img2, h, img.size(), z.typeInter);
resize(img2, img, imgOriginal.size());
imshow("test", img);
}
if (z.newPt || z.inter || modifZoom)
{
Rect r(z.p.x-50, z.p.y - 50,100,100);
resize(img(r),x,Size(),z.zoom,z.zoom);
imshow("zoom",x);
z.inter= false;
modifZoom=false;
}
}
waitKey();
}
2 | No.2 Revision |
That's not an answer. I am not able to reproduce your issue using this program but I think I don't understand your transformation. My program is :
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
struct ZoomPos {
Point p;
bool newPt;
int zoom;
int typeInter;
bool inter;
};
void AjouteGlissiere(String nomGlissiere, String nomFenetre, int minGlissiere, int maxGlissiere, int valeurDefaut, int *valGlissiere, void(*f)(int, void *), void *r)
{
createTrackbar(nomGlissiere, nomFenetre, valGlissiere, 1, f, r);
setTrackbarMin(nomGlissiere, nomFenetre, minGlissiere);
setTrackbarMax(nomGlissiere, nomFenetre, maxGlissiere);
setTrackbarPos(nomGlissiere, nomFenetre, valeurDefaut);
}
void onZoom(int event, int x, int y, int flags, void *userdata)
{
ZoomPos *z=(ZoomPos*)userdata;
if (event== EVENT_LBUTTONDOWN)
{
z->p = Point(x,y);
z->newPt=true;
}
else
z->newPt = false;
}
void MAJInter(int x, void * userdata)
{
ZoomPos *z = (ZoomPos*)userdata;
z->inter=true;
}
int main() {
ifstream fs;
fs.open("pp_sel_00000.fit",ios::binary);
if (!fs.is_open())
{
cout<<"PB";
return 0;
}
fs.seekg(0, ios_base::end);
int nb=fs.tellg();
int nb2=4008*2672*2;
cout<< nb+ -11 * 256 + 64<<" =? "<<nb2<<endl;
fs.seekg(11*256+64, ios_base::beg);
vector<char> v(nb2);
fs.read(v.data(),nb2);
Mat h=(Mat_<double>(3,3)<< -0.99974,- 0.00299,+ 4002.14396, +0.00239,- 0.99964,+ 2673.06210, -0.00000,- 0.00000, 1.00000);
for (int i = 0; i < v.size(); i += 2)
{
swap(v[i],v[i+1]);
}
Mat imgOriginal(2672,4008,CV_16SC1,v.data());
Mat img;
Mat img2;
ZoomPos z;
img=imgOriginal.clone();
resize(img,img,img.size()*2);
warpPerspective(img, img2, h, img.size(), CV_INTER_LANCZOS4);
resize(img2, img, imgOriginal.size());
namedWindow("test", WINDOW_NORMAL);
int code=0;
imshow("test",img);
z.p =Point(0,0);z.newPt = false; z.zoom = 1;z.inter=false;z.typeInter= CV_INTER_LANCZOS4;
AjouteGlissiere("Interpolation", "test", 0, CV_INTER_LANCZOS4, CV_INTER_LANCZOS4, &z.typeInter,MAJInter,&z);
setMouseCallback("test",onZoom,&z);
Mat x;
bool modifZoom=false;
while (code != 27)
{
code = waitKey(10);
switch (code){
case '+' :
if (z.zoom < 16)
{
modifZoom=true;
z.zoom += 1;
}
break;
case '-' :
if (z.zoom>=2)
{
modifZoom = true;
z.zoom -= 1;
}
break;
}
if (z.inter)
{
img = imgOriginal.clone();
resize(img, img, img.size() * 2);
warpPerspective(img, img2, h, img.size(), z.typeInter);
resize(img2, img, imgOriginal.size());
imshow("test", img);
}
if (z.newPt || z.inter || modifZoom)
{
Rect r(z.p.x-50, z.p.y - 50,100,100);
if (r.tl().x<0)
r.x = 0;
if (r.tl().y<0)
r.y = 0;
resize(img(r),x,Size(),z.zoom,z.zoom);
imshow("zoom",x);
z.inter= false;
modifZoom=false;
}
}
waitKey();
}
3 | No.3 Revision |
That's not an answer. I am not able to reproduce your issue using this program but I think I don't understand your transformation. My program is :
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
struct ZoomPos {
Point p;
bool newPt;
int zoom;
int typeInter;
bool inter;
};
void AjouteGlissiere(String nomGlissiere, String nomFenetre, int minGlissiere, int maxGlissiere, int valeurDefaut, int *valGlissiere, void(*f)(int, void *), void *r)
{
createTrackbar(nomGlissiere, nomFenetre, valGlissiere, 1, f, r);
setTrackbarMin(nomGlissiere, nomFenetre, minGlissiere);
setTrackbarMax(nomGlissiere, nomFenetre, maxGlissiere);
setTrackbarPos(nomGlissiere, nomFenetre, valeurDefaut);
}
void onZoom(int event, int x, int y, int flags, void *userdata)
{
ZoomPos *z=(ZoomPos*)userdata;
if (event== EVENT_LBUTTONDOWN)
{
z->p = Point(x,y);
z->newPt=true;
}
else
z->newPt = false;
}
void MAJInter(int x, void * userdata)
{
ZoomPos *z = (ZoomPos*)userdata;
z->inter=true;
}
int main() {
ifstream fs;
fs.open("pp_sel_00000.fit",ios::binary);
if (!fs.is_open())
{
cout<<"PB";
return 0;
}
fs.seekg(0, ios_base::end);
int nb=fs.tellg();
int nb2=4008*2672*2;
cout<< nb+ -11 * 256 + 64<<" =? "<<nb2<<endl;
fs.seekg(11*256+64, ios_base::beg);
vector<char> v(nb2);
fs.read(v.data(),nb2);
Mat h=(Mat_<double>(3,3)<< -0.99974,- 0.00299,+ 4002.14396, +0.00239,- 0.99964,+ 2673.06210, -0.00000,- 0.00000, 1.00000);
for (int i = 0; i < v.size(); i += 2)
{
swap(v[i],v[i+1]);
}
Mat imgOriginal(2672,4008,CV_16SC1,v.data());
Mat img;
Mat img2;
ZoomPos z;
img=imgOriginal.clone();
resize(img,img,img.size()*2);
warpPerspective(img, img2, h, img.size(), CV_INTER_LANCZOS4);
resize(img2, img, imgOriginal.size());
namedWindow("test", WINDOW_NORMAL);
int code=0;
imshow("test",img);
z.p =Point(0,0);z.newPt = false; z.zoom = 1;z.inter=false;z.typeInter= CV_INTER_LANCZOS4;
AjouteGlissiere("Interpolation", "test", 0, CV_INTER_LANCZOS4, CV_INTER_LANCZOS4, &z.typeInter,MAJInter,&z);
setMouseCallback("test",onZoom,&z);
Mat x;
bool modifZoom=false;
Ptr<Mat> lutRND;
if (!lutRND)
{
RNG ra;
lutRND = makePtr<Mat>(256, 1, CV_8UC3);
ra.fill(*lutRND, RNG::UNIFORM, 0, 256);
}
while (code != 27)
{
code = waitKey(10);
switch (code){
case '+' :
if (z.zoom < 16)
{
modifZoom=true;
z.zoom += 1;
}
break;
case '-' :
if (z.zoom>=2)
{
modifZoom = true;
z.zoom -= 1;
}
break;
}
if (z.inter)
{
img = imgOriginal.clone();
resize(img, img, img.size() * 2);
warpPerspective(img, img2, h, img.size(), z.typeInter);
resize(img2, img, imgOriginal.size());
imshow("test", img);
}
if (z.newPt || z.inter || modifZoom)
{
Rect r(z.p.x-50, z.p.y - 50,100,100);
if (r.tl().x<0)
r.x = 0;
if (r.tl().y<0)
r.y = 0;
resize(img(r),x,Size(),z.zoom,z.zoom);
imshow("zoom",x);
Mat x3;
x=x/256;
(x).convertTo(x3,CV_GRAY2BGR);
applyColorMap(x3,x3, *lutRND.get());
imshow("zoom",x3);
z.inter= false;
modifZoom=false;
waitKey(10);
cout<<"-->\n";
}
}
waitKey();
}