因此,我需要使用 zig zag 扫描将 8x8 的 opencv mat 转换为扁平矢量,如图所示。
我了解它应该做什么,并且我认为我已经完成了前半部分的实现,但是当我尝试将值设置为向量时收到错误消息。
std::vector<float> *ZigZagScanner::scan(cv::Mat &input) {
std::vector<float> *output = new std::vector<float>();
// TODO Traverse the input in a zigzag scan, and store the result in output
//set row and column start values to zero, set increment flag to false
// TODO Traverse the input in a zigzag scan, and store the result in output
//set row and column start values to zero, set increment flag to false
int row, col = 0;
bool increment = false;
//create nest for loops to traverse through the first half of the matrix in a zig zag fashion
for(int y = 1; y <= 8; ++y){
for(int x = 0; x < y; ++x){
//add the current row and column to the flatten vector
//ERROR HERE
cv::Rect rect = cv::Rect(y,x, 8, 8);
output->push_back(new cv::Mat(input, rect));
if(x + 1 == y){
break;
}
//when the increment flag is true increase the row and decrease the column
if(increment == true){
++row, --col;
}
else{
--row, ++col;
}
}
//if y gets to out of bounds break the loop
if(y == 8){
break;
}
//if the increment flag is true then increment the row and switch the flag, otherwise increment the column and swap the flag
if(increment == true){
++row, increment = false;
}
else{
++col, increment = true;
}
}
//update the columns and rows to the correct values to go through the second half of the matrix
if(row == 0){
if(col == 7){
++row;
}
else{
++col;
increment = true;
}
}
else{
if(row == 7){
++col;
}
else{
++row;
increment = false;
}
}
for(int k, j = 7; j > 0; --j){
if(j > 8){
k = 8;
}
else{
k = j;
}
for(int i = 0; i < k; i++){
//ERROR HERE AS WELL
cv::Rect rect = cv::Rect(y,x, 8, 8);
output->push_back(new cv::Mat(input, rect));
}
}
在这一点上,我只是在努力弄清楚这部分,任何建议都意味着很多!返回输出;}